Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Join with distinct values

Tags:

mysql

Table Name : x

id name id is primary key

1   xxxx
2   yyyy

Table name : y
sno primary key id foreign key class

1 1 first 
2 1  second

OUTPUT

id 
xxxx first second

I do not want name to repeat for each row

SELECT x.name, y.class from x,y  WHERE x.id = y.id

This query output as xxxx first and xxxx second


1 Answers

Add in GROUP BY y.id then to avoid duplicate.

like image 138
sel Avatar answered May 13 '26 10:05

sel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!