Solved

query question

Posted on 2016-10-18
4
26 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
  • 2
  • 2
4 Comments
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 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 12

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now