Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query without getting duplicate data?

Tags:

mysql

I have a query which has a join on another table:

select * from tbl_scales s
join tbl_recipes r on r.category_id = s.product_id

and it displays redundant data like this,

scale_id    r_id     date       recipe_name

1       1   2012-05-20  Cheese Bread
6       1   2012-05-21  Cheese Bread
1       1   2012-05-20  Spanish Bread
6       1   2012-05-21  Spanish Bread
3       4   2012-05-20  Pancake
8       4   2012-05-21  Pancake
1       1   2012-05-20  Pandesal
6       1   2012-05-21  Pandesal

i don't know how to do this..can someone help me?

like image 656
Tsukimoto Mitsumasa Avatar asked Jul 31 '26 22:07

Tsukimoto Mitsumasa


2 Answers

SELECT DISTINCT will eliminate rows that have equal data in columns. But since your date is different you probably want to use GROUP BY recipe_name (add on the end of your query).

like image 179
cen Avatar answered Aug 06 '26 02:08

cen


The distinct keyword is your friend.

select distinct r_id, scale_id, recipe_name from tbl_scales s
join tbl_recipes r on r.category_id = s.product_id
like image 33
Jeshurun Avatar answered Aug 06 '26 04:08

Jeshurun



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!