I have 2 Tables. CustomerDetails table has columns ID, UUID, Name, Age. FavoriteCustomers table has columns ID, UUID
CustomerDetails Table will have a lot of entries say 10000 rows. while FavoriteCustomers Table has very few entries. In CustomerDetails Table, ID and UUID form the combined unique ID.
Now I want the result to be combined row columns like below with a where clause.
ID, UUID, Name, Age, isFavorite WHERE Age is > 30
Advertisement
Answer
In DBMS that support some kind of a boolean type you can use an EXISTS
clause or an IN
clause.
select id, uuid, name, age, (id, uuid) in (select id, uuid from favoritecustomers) as is_favorite from customerdetails where age > 30;