?
Solved

Need help with correct nested query syntax

Posted on 2009-04-30
6
Medium Priority
?
226 Views
Last Modified: 2012-05-06
I am trying to create a nested query that reads like this:

SELECT * FROM services_tbl WHERE services_tbl.foreignkeyID
EXISTS (SELECT * FROM foreignkey_tbl WHERE foreignkey_tbl.foreignkeyID = 300)

I keep getting an error and can't seem to figure out how to do it correctly. If possible I would like to not have to change the first half of the statement "SELECT * FROM services_tbl WHERE".
0
Comment
Question by:nbotts
  • 3
  • 3
6 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24271755
SELECT * FROM services_tbl
WHERE services_tbl.foreignkeyID
AND
EXISTS (SELECT * FROM foreignkey_tbl WHERE foreignkey_tbl.foreignkeyID = 300)
0
 

Author Comment

by:nbotts
ID: 24271839
When I tried that the error said: "An expression of non-boolean type specified in a context where a condition is expected, near 'AND'."
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24272013
ohh my mistake

SELECT * FROM services_tbl
WHERE  EXISTS (SELECT 1 FROM foreignkey_tbl WHERE foreignkey_tbl.foreignkeyID = 300)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:nbotts
ID: 24273496
That doesn't make sense to me. I don't see how that accomplishes my goal.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24275260

SELECT * FROM services_tbl
WHERE  EXISTS (SELECT 1 FROM foreignkey_tbl WHERE foreignkey_tbl.foreignkeyID = services_tbl.foreignkeyID )
0
 

Author Comment

by:nbotts
ID: 24280373
Thanks aneeshattingal, that got me here which seems to do the job:

SELECT * FROM services_tbl
WHERE services_tbl.foreignkeyID
IN (Select foreignkeyID From foreignkey_tbl WHERE foreignkey_tbl.foreignkeyID = services_tbl.foreignkeyID)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

839 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