Solved

Select only if count results type > 0 in detail table

Posted on 2014-03-10
2
599 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
Comment Utility
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
Comment Utility
Perfect. Thank you so much for your help and quick reply.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now