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
Solved

Very simple MSSQL syntax question

Posted on 2009-04-11
3
164 Views
Last Modified: 2012-05-06
Hi,

Why does this query give me a syntax error in MS SQL Server?

select dv_id, dp_id from em where dv_id, dp_id not in (select dv_id, dp_id from dp)

I'm just trying to check for invalid data for a foreign key referencing a two-part primary key.

What is the correct syntax for this? Thanks in advance.
0
Comment
Question by:algernon23
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 24121882
this will do:
select dv_id, dp_id from em where not exists (select null from dp where dp.dv_id = em.dv_id and dp.dp_id = em.dp_id) 

Open in new window

0
 
LVL 11

Expert Comment

by:bmatumbura
ID: 24121884
Your subquery (select dv_id, dp_id from dp) must not return multiple fields if you want to use the NOT in clause
0
 

Author Closing Comment

by:algernon23
ID: 31569162
Thank you for your help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SYbase 4 36
Syntax for query to update table 2 29
Using SQL*PLUS issue with where statement with trunc function 3 27
Accessing variables in MySQL query 4 21
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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