Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

Select only if count results type > 0 in detail table

Hi,

I'm using sqlite. I have 2 tables. One is a detail table. I want to select all the records in table 1 only if they have details in table 2 where the column "type" equals "List"

select * from Vehicles

having

select count > 0 from list_detail where type = "List"

Any help would be greatly appreciated.

-S
0
summerset
Asked:
summerset
1 Solution
 
Terry WoodsIT GuruCommented:
I think you want something like this; I'm not familiar with sqlite but hopefully it allows standard syntax.
select * 
from Vehicles
where exists
 (select * from list_detail 
where type="list" 
and some_other_column = Vehicles.some_other_column)

Open in new window

You'll need to change "some_other_column" to the name of the columns used to join the two tables; you didn't specify that in your question.
0
 
summersetAuthor Commented:
Perfect. Thank you so much for your help and quick reply.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now