如何优化几个“WHERE (Select ....) = value”来自同一张桌子
对我来说很难起一个主题名称。但我可以举一个例子:
WHERE (SELECT [ID_Line] FROM [Event] WHERE [Event].[Name] = [A].[Col]) = 2
AND (SELECT [DataType] FROM [Event] WHERE [Event].[Name] = [A].[Col]) = 2
在这里,当我确实需要类似的东西时,我正在处理 2 个查询:
WHERE (SELECT [ID_Line],[DataType] FROM [Event] WHERE [Event].[Name] = [A].[Col]) = 2,2
但是 SQL 不适用于元组,所以我必须在这里进行 Inner Join 吗?
It's hard to compose a topic name for me. But I can show an example :
WHERE (SELECT [ID_Line] FROM [Event] WHERE [Event].[Name] = [A].[Col]) = 2
AND (SELECT [DataType] FROM [Event] WHERE [Event].[Name] = [A].[Col]) = 2
Here I'm processing 2 queries when I really need something like that :
WHERE (SELECT [ID_Line],[DataType] FROM [Event] WHERE [Event].[Name] = [A].[Col]) = 2,2
but SQL doesn't work with tuples, so must I make Inner Join here ?
您可以尝试这样的操作:
如果您提供有关完整查询和数据库结构的更多信息,则可以给出更准确的答案。这可能不是最好的解决方案。
you can try something like this :
If you provide more information about the complete query and your database structure, a more precise answer could be given. It is possible that this isn't the best solution.