php - How to SELECT data from two tables which only first row of second table is selected for one row of first table
985
Table 1 contains fields: tab1_id name, description
Table 2 contains fields: tab2_id,id,choice.
By using the following query
SELECT * FROM table1 AS t1
INNER JOIN table2 AS t2
ON t1.tab1_id=t2.id
it returned several rows of table2 for each t1.tab1_id.
What I want is to get only first row of table2 for each ta.tab1_id.
Please help.
Answer
Solution:
Just use a GROUP BY, just make sure to include every column in your GROUP BY that you want to use in your SELECT clause, i.e.: