我有三個表* book_category,books和book_pictures *在我的mysql中。我想獲得每本書類別的最新書籍訂單通過修正。我使用這個查詢來獲取最新的書籍,它工作正常。從每個類別的多個表中選擇最新的記錄
select * from (select * from books ORDER BY amended DESC) AS x GROUP BY book_sub_category_id
,但我想加入我的book_pictures表,所以我得到book_pictures URL來顯示圖像的書。如何編寫查詢以從book_pictures表中獲取最新書籍的URL?下面我告訴你表的結構。
book_category
+-------------+-----------------+
|category_id | category_name |
|-------------------------------|
| ca | custom Act |
| ct | Custom Tarif |
|-------------+-----------------+
books
+-------------+-----------------+-----------------+--------------------------+
| book_id | category_id | name | amended |
|-------------------------------|-----------------+--------------------------|
| 01 | ca | custom Act | 01-06-2011 |
| 02 | ca | custom Act | 01-06-2012 |
| 03 | ca | custom Act | 01-06-2013 |
| 04 | ct | custom tarif | 01-07-2011 |
| 05 | ct | custom tarif | 01-07-2012 |
| 06 | ct | custom tarif | 01-07-2013 |
+-------------+-----------------+-----------------+--------------------------+
book_pictures
+-------------+-----------------+-----------------+--------------------------+
| picture_id | book_id | small_url | large_url |
|-------------------------------|-----------------+--------------------------|
| p1 | 01 | url | url |
| p2 | 02 | url | url |
| p3 | 03 | url | url |
| p4 | 04 | url | url |
| p5 | 05 | url | url |
| p6 | 06 | url | url |
+-------------+-----------------+-----------------+--------------------------+
你怎麼定義最新?通過book_id? – Pirion
按日期排列。 – user2087078