Select * from table where ID list is on another table
use temp1
select * from [TZraw].[dbo].[A1]
where [TZraw].[dbo]开发者_JAVA百科.[A1].[ID] in [select F1 from info1]
I am trying to select all the records from TZraw table A1 that match every record in temp1 table F1
Use parenthesis:
select * from [TZraw].[dbo].[A1]
where [TZraw].[dbo].[A1].[ID] in (select F1 from info1)
Instead of square brackets on the subselect.
Try round brackets for the subquery:
use temp1
select * from [TZraw].[dbo].[A1]
where [TZraw].[dbo].[A1].[ID] in (select F1 from info1)
You need parenthesis for the IN
clause
select * from [TZraw].[dbo].[A1]
where [TZraw].[dbo].[A1].[ID]
in (select F1 from info1)
try this in your query
... in (select F1 from info1)
Your SQL syntax is incorrect - the subquery should be in parens - ()
, not square braces []
.
Use a join instead of a subquery - SQL is better optimized for it:
SELECT first.*
FROM [TZraw].[dbo].[A1] AS first
INNER JOIN info1 AS second
ON first.ID = second.F1
Try to create a temporary table
Select * From Tzrav ti Where .... ti...<>t...
REATE TEMPORARY TABLE SalesSummary ( Select* From Temp1 t Where .... )
精彩评论