all groups > sql server (alternate) > october 2006 >
You're in the

sql server (alternate)

group:

making JOINS



making JOINS MORALBAROMETER
10/20/2006 8:19:46 AM
sql server (alternate): Hi alll
I have these tables below with 3 fields each. I want to get the record
in table 1 whose field number value is same in table 2 but field number
2 on both tables are different. I mean i want the record
1500 800 2. Insight: Table 1 is modules ordered and table 2 is modules
delivered. I want to get 1500 800 2.beacuse module 800 was ordered but
in table 2 module 503 was delivered. can some one help me with a join

nice weekeend

Table 1

10 5012 10
1600 502
100 502 3
1500 800 2




Table 2

1500 503 1
1400 4000
100 502 10
100 600
100 502 3
Re: making JOINS DA Morgan
10/20/2006 8:51:21 AM
[quoted text, click to view]

Write a statement where:
field1 = field1
and
field2 <> field2
--
Daniel A. Morgan
University of Washington
damorgan@x.washington.edu
Re: making JOINS MORALBAROMETER
10/23/2006 12:52:26 AM
Hi Daniel,
thanks alot for the prompt reply. this is what i had:

100 502
100 502
1500 800

as seen in the table 100 502 was ordered and shipped but more articles
were shipped not ordered by customerID(100). I do not need this
information. I need a list where a customer ordered and received
shippment where no product ordered was shipped. in this case
customer(1500) should be the right answer. He ordered and recived
shippement but within the list no article oredered was shiped. but
customer (100) received the ordered product plus some extra
Hope to read from u and any one else




[quoted text, click to view]
Re: making JOINS Hugo Kornelis
10/25/2006 11:53:16 PM
[quoted text, click to view]

Hi MORALBAROMETER,


Maybe something like this?

SELECT o.CustomerID, o.ArticleID
FROM Orders AS o
LEFT JOIN Shipments AS s
ON s.CustomerID = o.CustomerID
AND s.ArticleID = o.ArticleID
WHERE s.CustomerID IS NULL

or the following (logically equivalent, but easier to understand for
beginning SQL coders):

SELECT o.CustomerID, o.ArticleID
FROM Orders AS o
WHERE NOT EXISTS
(SELECT *
FROM Shipments AS s
WHERE s.CustomerID = o.CustomerID
AND s.ArticleID = o.ArticleID)

If these are not what you're after, then I recommend that you post your
table structure (as CREATE TABLE statements, including constraints,
properties and indexes), some rows of sample data (as INSERT statements)
and expected results. See www.aspfaq.com/5006 for more info.

--
AddThis Social Bookmark Button