?
Solved

query question

Posted on 2016-10-18
4
Medium Priority
?
38 Views
Last Modified: 2016-10-18
Hi,

I have two sample tables, how can I come up with the result that shows everything from V and left 3, 5 in S as null

SELECT     v.vid, v.vname, s.sid, s.sname
FROM         service s LEFT  JOIN
                      visit v ON s.sid = v.vid
WHERE s.sid not in (3,5)

thanks
c1.JPG
c2.JPG
0
Comment
Question by:mcrmg
[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
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Dustin Saunders earned 2000 total points
ID: 41849185
SELECT v.vid,v.vname,s.sid,s.sname
FROM visit v
LEFT JOIN service s ON v.vid = s.sid AND s.sid NOT IN (3,5)

Open in new window


Should do that.
Results:
vid         value                                              sid         sname
----------- -------------------------------------------------- ----------- --------------------------------------------------
1           m                                                  1           aaa
2           m                                                  2           bbb
3           m                                                  NULL        NULL
4           w                                                  4           ddd
5           w                                                  NULL        NULL
6           w                                                  6           fff
7           w                                                  NULL        NULL
8           w                                                  NULL        NULL
9           m                                                  NULL        NULL
10          m                                                  NULL        NULL

Open in new window

0
 

Author Comment

by:mcrmg
ID: 41849194
is there another to do this?  thanks
0
 
LVL 13

Expert Comment

by:Dustin Saunders
ID: 41849197
There might be, though this is the simplest route.  Is that not the result you needed?
0
 

Author Closing Comment

by:mcrmg
ID: 41849200
thank you very much
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

764 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