Solved

Select only if count results type > 0 in detail table

Posted on 2014-03-10
2
620 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

623 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