Solved

query question

Posted on 2016-10-18
4
34 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

856 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