Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to 'join' when t1.id != t2.id

Status
Not open for further replies.

bMindful

Programmer
Dec 22, 2003
3
US
Hi,

I've tried to search for what I expect to be an easy solution, but I've been searching a lot and at heart would still rather just do a subselect ;) but MySQL is sublime nonetheless.

My need is to only select items in table 1 that ARE NOT in table two. Table one is a catalog list, and table two is a list of reserved items that are no longer available to offer.

Since joins require matching on the foreign key, how do I do this when I want all items in table 1 that do not match a foreign key in table 2

Here's a simplifications of what I'm attempting. Can you show me the light? Gratzie!

Code:
SELECT catalog_item.item_id FROM catalog_item, reserved_item WHERE catalog_item.item_id != reserved_item.item_id
 
Presumption Resevered Iyems table is a subset of catalog item
Code:
SELECT catalog_item.item_id FROM catalog_item 
	left join reserved_item 
	on cataolog_item.item_id = reserved_item.item_id
WHERE reserved_item.item_id is null







[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top