salt-pepper
salt-pepper

Reputation: 125

sql query to return records from two columns

I have a table with id (PK), type, sub-type

id type sub-type
1 address1 type1
2 address1 type2
3 address2 type1
4 address2 type 3
5 address1 type3

I want my query to return all values where address1 is IN type1, type3 and address2 with type1

select * from information e  where e.type IN (SELECT type  from information ev where ev.type = 'address1' AND `sub-type` IN ('type1', 'type3') )

But this does not return me type1, type3 and I am not able to build further with this query for both types

Upvotes: 0

Views: 34

Answers (1)

juergen d
juergen d

Reputation: 204766

SELECT * 
FROM information e  
WHERE (e.type = 'address1' AND `sub-type` IN ('type1', 'type3'))
   OR (e.type = 'address2' AND `sub-type` = 'type1')

Upvotes: 1

Related Questions