sibimani
sibimani

Reputation: 95

Get distinct value from join query (Join Table)

How get a distinct value form more than one table (inner join query).

Eg,

select a.id,b.name,c.address 
from table1 a 
inner join table2 b on (a.id = b.row_id)
inner join table3 c on (a.id = c.ticket_id)
where c.status = 'open';

Here the scenario is for example, two rows contain the same a.id value so how to get the distinct value from a.id.

Somebody help me that how to get?

Upvotes: 0

Views: 265

Answers (1)

user1713815
user1713815

Reputation:

just add Distinct ...

select DISTINCT a.id,b.name,c.address 
from table1 a 
inner join table2 b on (a.id = b.row_id)
inner join table3 c on (a.id = c.ticket_id)
where c.status = 'open';

i think this is works fine..

if you need only one record distinct then it should be like this...

SELECT DISTINCT(cat_id) FROM PRODUCTS WHERE brand_id = 'sony'

Upvotes: 1

Related Questions