Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 New to SQL Server 2008 Need some Help

Author  Topic 

gully24
Starting Member

2 Posts

Posted - 2012-02-13 : 00:30:21
Trying to understand the inner and outer Joins any help with this Query would help me greatly thanks in advance.

Write query, the customers and orders table, that will show all of the customers with the orders they have placed – if they have placed an order or not in customer id order?

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-13 : 03:57:00
What have you got so far?

I'm not going to do your homework for you.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

gully24
Starting Member

2 Posts

Posted - 2012-02-13 : 09:56:46
SELECT *

FROM Orders o

RIGHT OUTER JOIN Customers c

ON c.CustomerID = o.CustomerID

ORDER BY c.CustomerID

--PART2--

--SELECT c.CustomerID,o.*

--FROM Orders o

--RIGHT OUTER JOIN Customers c

--ON c.CustomerID = o.CustomerID

--WHERE o.CustomerID IS NULL

--ORDER BY c.CustomerID
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-02-13 : 10:00:48
Ok, and what's wrong with those? What are they not doing that they should, etc?

p.s. The second is looking for orders that don't have customers. Is that even possible?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-02-13 : 10:29:31
To get you off on the "right" foot, I would suggest you shelve using RIGHT JOINs for now


SELECT *
FROM Customers c
LEFT JOIN Orders o
ON c.CustomerID = o.CustomerID
ORDER BY c.CustomerID




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -