You are here: NOT EXISTS using single table? « MsSQL Server « IT news, forums, messages
NOT EXISTS using single table?

Posted by Artie on 01/22/08 20:09

My pee-brain cannot seem to grasp what seems quite simple.
I am trying to query a single table that stores items and their warehouse
locations to find items that do not exist in a particular warehouse.
There are plenty of examples of this with 2 tables like:

This query finds the titles for which there have been no sales.
USE pubs
SELECT title
FROM titles
WHERE NOT EXISTS
(SELECT title_id
FROM sales
WHERE title_id = titles.title_id)
Given this sample data:CREATE TABLE [ItemLoc] ( [item] [varchar] (10) NOT
NULL , [loc] [char] (2) NOT NULL , )GOINSERT ItemLoc
VALUES('ABC','CA')INSERT ItemLoc VALUES('ABC','NY')INSERT ItemLoc
VALUES('ABC','FL')INSERT ItemLoc VALUES('CDE','CA')INSERT ItemLoc
VALUES('CDE','FL')INSERT ItemLoc VALUES('CDE','OH')INSERT ItemLoc
VALUES('FGH','CA')INSERT ItemLoc VALUES('FGH','OH')What query will show
items that DO NOT exist in loc 'OH'. Should only show item 'ABC'Or items
NOT IN loc 'NY'. Should show items 'CDE' and 'FGH'Thanks.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация