Dovberman
asked on
Tsql to Select Rows Based on a Condition
I have two tables.
I need to select rows in one table based on the number of times a common field occurs in the other table.
Table 1: Exceptions, Common field: SymbolID
Table 2: StockHist, Common field: SymbolID
SELECT SymbolID FROM Exceptions
WHERE Count(Exceptions.SymbolID) in StockHist is less than or equal to 5
Thanks,
I need to select rows in one table based on the number of times a common field occurs in the other table.
Table 1: Exceptions, Common field: SymbolID
Table 2: StockHist, Common field: SymbolID
SELECT SymbolID FROM Exceptions
WHERE Count(Exceptions.SymbolID)
Thanks,
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All three work.
Can the following be used to delete Exception table rows where the Exception.SymbolID occurs less than 5 times in the StockHist table? I do not want to delete StockHist rows.
DELETE FROM Exceptions EX
INNER JOIN StockHist SH
ON SH.SymbolID = EX.SymbolID
GROUP BY EX.SymbolID
HAVING COUNT(EX.SymbolID) <= 5
Can the following be used to delete Exception table rows where the Exception.SymbolID occurs less than 5 times in the StockHist table? I do not want to delete StockHist rows.
DELETE FROM Exceptions EX
INNER JOIN StockHist SH
ON SH.SymbolID = EX.SymbolID
GROUP BY EX.SymbolID
HAVING COUNT(EX.SymbolID) <= 5
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wish to thank all of you.
ASKER
Thanks,