0

这是我的两张桌子:

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”表包含有关年份和标签的信息。

4

1 回答 1

1
SELECT DISTINCT
  tunes.riddim AS riddim,
  tunes.year AS year.
  riddims.image AS image,
  runes.label AS label
FROM riddims
INNER JOIN tunes ON riddims.riddim=tunes.riddim
WHERE tunes.year="2012"
ORDER BY riddims.last_modified
LIMIT 20
;
于 2012-09-08T20:25:35.763 回答