Greetings community,
Another newbie's question I have to ask.
It’s part of more complicated problem but for simplicity let’s say that I have two tables:
Table Items:
ItemID (PK,autoincrement) | ItemName |
1 | Item1 |
2 | Item2 |
3 | Item3 |
4 | Item4 |
5 | Item5 |
6 | Item6 |
Table SelectedItems
SelectedID (PK,autoincrement) | SelItemID |
1 | 3 |
2 | 4 |
Simply: table Items is lookup table that holds names of items and table SelectedItems holds IDs of items that are selected so far. I want to prevent user to select some item twice. So I need stored procedure that would return those items that are not selected yet. In the case presented here that would be
ItemID (PK,autoincrement) | ItemName |
1 | Item1 |
2 | Item2 |
5 | Item5 |
6 | Item6 |
I’m a bit reluctant to ask, because it feels unnatural, but is it possible to join two tables on some fields that are not equal:
Select a.ItemID, a.ItemName from Items a join SelectedItems b on a.ItemID<>b.SelItemID
I’m still new with T-SQL and JOIN so I need to ask if join on is supposed to work only with equal sign or I can make any expression
Thanks for any help.