December 9, 2009 at 12:37 pm
i have two tables. One is Parts( partnbr, desc,qty)
Second is ExclusionList(partnbr,desc)
Now i want to select rows from parts table excluding part nbrs which are present in exclusionlist table.
Something like this:-
select * from parts where partnbr <> (select partnbr from exclusionlist)
I dont know how to do that can anyone help me with this?
Thanks
December 9, 2009 at 12:45 pm
Your thread name indicates counting rows in table and you say in your reply, select rows.
Any way.
To Count rows
SELECT COUNT(*) FROM parts where partnbr not in
(SELECT DISTINCT partnbr FROM ExclusionList)
To display all rows
SELECT * FROM parts where partnbr not in (SELECT DISTINCT partnbr FROM ExclusionList)
If you only need top display the partnbr,
SELECT partnbr FROM parts
EXCEPT
SELECT partnbr FROM ExclusionList
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
December 9, 2009 at 12:54 pm
Solution:-
SELECT COUNT(*) AS Expr1
FROM (SELECT partnbr
FROM Parts
WHERE (partnbr NOT IN
(SELECT partbr
FROM exclusionlist))) DERIVEDTBL
December 9, 2009 at 12:59 pm
schauhan13 (12/9/2009)
Solution:-SELECT COUNT(*) AS Expr1
FROM (SELECT partnbr
FROM Parts
WHERE (partnbr NOT IN
(SELECT partbr
FROM exclusionlist))) DERIVEDTBL
What big difference does it have with the first SQL Code given by me?
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
December 9, 2009 at 11:05 pm
Bru Medishetty (12/9/2009)
schauhan13 (12/9/2009)
Solution:-SELECT COUNT(*) AS Expr1
FROM (SELECT partnbr
FROM Parts
WHERE (partnbr NOT IN
(SELECT partbr
FROM exclusionlist))) DERIVEDTBL
What big difference does it have with the first SQL Code given by me?
Heh... nothing, except... 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
December 10, 2009 at 1:03 am
How 'bout:
;with
ValidParts(partnbr) as(
select partnbr from Parts
except
select partnbr from ExclusionList)
select count(1) ReportedParts from ValidParts
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply