[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

query question

Posted on 2016-10-18
4
Medium Priority
?
41 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 14

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 14

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

872 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