Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
表 1 包含字段:tab1_id 名称、描述
表 2 包含字段:tab2_id,id,choice。
通过使用以下查询
SELECT * FROM table1 AS t1 INNER JOIN table2 AS t2 ON t1.tab1_id=t2.id
它为每个 t1.tab1_id 返回了几行 table2。
我想要的是只为每个 ta.tab1_id 获取 table2 的第一行。
请帮忙。
只需使用 GROUP BY,只需确保在 GROUP BY 中包含要在 SELECT 子句中使用的每一列,即:
SELECT * FROM table1 AS t1 JOIN table2 AS t2 ON t1.tab1_id=t2.id GROUP BY t1.tab1_id ;