Solved

Select only if count results type > 0 in detail table

Posted on 2014-03-10
2
608 Views
Last Modified: 2014-03-10
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
Comment
Question by:summerset
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 39919532
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
 

Author Comment

by:summerset
ID: 39919741
Perfect. Thank you so much for your help and quick reply.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question