Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL select query problem

Posted on 2011-05-10
3
Medium Priority
?
174 Views
Last Modified: 2012-05-11
Hello EE,

Let'say i have 2 tables.

First table has:   ID, Description
Second has ID, (same id that table1)

in first table i have values:    1,2,3,4,5

how can I do a SELECT that if there is nothing in table 2  it returns  1,2,3,4,5  if lets say there is 1 and 3 it will return 1,2,4,5

lets say in table 2 there is 4,5  it would return 1,2,3

can y u help ?
0
Comment
Question by:PhilippeRenaud
3 Comments
 
LVL 33

Accepted Solution

by:
knightEknight earned 2000 total points
ID: 35728698
select *
from Table1
where ID not in (select distinct ID from Table2)
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35728739

select ID, Description
from table1
left join table2 on table2.id = table1.id
where table2.id is null
0
 
LVL 1

Author Comment

by:PhilippeRenaud
ID: 35728743
ahh...thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

810 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