How to optimize multiple "WHERE (Select ....) = value" from the same table

I find it difficult to make 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 process 2 requests when I really need something like this:

WHERE   (SELECT [ID_Line],[DataType] FROM [Event] WHERE [Event].[Name]  = [A].[Col]) = 2,2

but SQL doesn't work with tuples, so should I do Inner Join here?

+3
source share
2 answers

you can try something like this:

WHERE EXISTS (
    SELECT [ID_Line] FROM [Event] WHERE
        [Event].[Name]  = [A].[Col] AND
        [Event].[ID_Line] = 2 AND
        [Event].[DataType] = 2
)

If you provide more detailed information about the full query and the structure of the database, you can give a more accurate answer. This may not be the best solution.

+7
source

You can try to melt the fields using the melting operator. In ORACLE PL / SQL, you use || (dual channel), for example.

0
source

All Articles