我有三个表* 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