这是我的两张桌子:
mysql> desc riddims;
+---------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+-------+
| riddim | varchar(255) | NO | MUL | NULL | |
| genre | varchar(9) | NO | | NULL | |
| youtube | varchar(11) | NO | | NULL | |
| image | varchar(11) | NO | | NULL | |
| last_modified | timestamp | NO | | CURRENT_TIMESTAMP | |
+---------------+--------------+------+-----+-------------------+-------+
5 rows in set (0.00 sec)
mysql> desc tunes;
+---------------+--------------+------+-----+-------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+-------------------+-------+
| riddim | varchar(255) | NO | MUL | NULL | |
| artist | varchar(255) | NO | MUL | NULL | |
| tune | varchar(255) | NO | | NULL | |
| label | varchar(255) | NO | | NULL | |
| producer | varchar(255) | NO | | NULL | |
| year | varchar(4) | NO | | NULL | |
| lyrics | text | NO | | NULL | |
| flag | varchar(12) | NO | | NULL | |
| last_modified | timestamp | YES | | CURRENT_TIMESTAMP | |
+---------------+--------------+------+-----+-------------------+-------+
到目前为止我得到的是
SELECT DISTINCT riddim FROM tunes WHERE year = '2012' ORDER BY last_modified DESC LIMIT 20
它打印“riddim”列的最后 20 个添加/修改的条目。如何将有关“riddims”表中每个riddim 的正确信息添加到从“tunes”表中抓取的每一行?
我假设我必须以某种方式使用“riddim”列加入它们,因为这是两个表共有的“关键”,我只是不知道它是如何工作的。
我的目标是打印今年最后 20 个riddims 条目的“riddim、year、image、label”(使用 php),其中只有“tunes”表包含有关年份和标签的信息。