I have two tables:
Thus there may be multiple rows in ITEMDESCRIPTION for each ITEM record.
I need to find all items for a specific account that have two specific values in any of the corresponding ITEMDESCRIPTION table's ItemDesc field
So far I've come up with as an example:
which certainly gets the correct results but I feel that I'm missing something and there should be a better way to do this.
I'm using SQL Server 2005 so any useful extensions in this version may be used. The options of using functions, stored procedures or temporary tables are not open to me unfortunately.
Any ideas?
Bob Boffin
Code:
ITEM
ItemID INT (PK)
AccountID INT
.
.
ITEMDESCRIPTION
ItemID INT ) (PK)
Sequence INT )
ItemDesc NVARCHAR(255)
I need to find all items for a specific account that have two specific values in any of the corresponding ITEMDESCRIPTION table's ItemDesc field
So far I've come up with as an example:
Code:
SELECT ItemID
FROM ITEM I
WHERE I.AccountID=173 AND
(SELECT COUNT(*) FROM ITEMDESCRIPTION D1 WHERE D1.ItemID=I.ItemID AND (D1.ItemDesc LIKE '%davidson%')) <> 0 AND
(SELECT COUNT(*) FROM ITEMDESCRIPTION D2 WHERE D2.ItemID=I.ItemID AND (D2.ItemDesc LIKE '%sarah%')) <> 0
I'm using SQL Server 2005 so any useful extensions in this version may be used. The options of using functions, stored procedures or temporary tables are not open to me unfortunately.
Any ideas?
Bob Boffin