MySQL Select distinct values from two table that have a common key -
i making query using 3 table. quotes table has key called quote_id stored in quote_items table. there ever 1 instance of quote_id in quotes table in quote_items table may occur several times. want join 2 together, filter out instance quote_id occurs more once.
select * quotes inner join quote_items on quotes.quote_id in (select distinct quote_id quote_items) inner join accounts on quotes.account_id = accounts.account_id , quotes.status = 0 primary_sales_id = 2 , quotes.quote_id = quote_items.quote_id order quotes.date_submitted desc
you can ignore account_id part. line 3 should different, know, how go i'm not sure.
if had quotes looking this
quote_id | quote_name 1 | quote1 2 | qute2
and quote_items looking this
quote_id | item_name 1 | boards 2 | nails 2 | blocks
i should
quote_id | quote_name | item_name 1 | quote1 | boards 2 | quote2 | nails
you may use:
select distinct quotes.quote_id, quote_name, item_name quotes, quote_items quotes.quote_id = quote_items.quote_id group (quote_id );
Comments
Post a Comment