Query two records in the same SQL Server table

1

I would like you to resolve this doubt.

I want to make a query of a user table, but I want to do it so that I can display two results, since I want to compare the information of two users.

When I make a normal query it would be like this:

SELECT * FROM seUser WHERE ID_User = '1'

and it displays the user's information with ID 1. Now, what I want to add is that the query also displays the user's information with ID 23, I hope I could have explained myself well.

    
asked by Gio Gómez 05.07.2017 в 23:43
source

3 answers

1

The long query:

SELECT * FROM seUser WHERE ID_User = '1' OR ID_User = '27'

and the short form (using the operator IN ):

SELECT * FROM seUser WHERE ID_User IN('1','27')

Note: if ID_User is numeric it should not be enclosed in quotes.

    
answered by 06.07.2017 / 00:46
source
0

it's really easy to use the logical operators like and "and", or "0", xor "and-o",

example and SELECT * FROM seUser WHERE ID_User = '1' and ID_User = '27' if the two IDs exist, it will return a result of the two that you request, but if there is only 1, it will not return anything example or SELECT * FROM seUser WHERE ID_User = '1' or ID_User = '27' in this case, it does the opposite if there is either one that brings you that row regardless of whether the other does not exist.

    
answered by 08.07.2017 в 02:28
-2

I guess that doing two views is enough ...

  

SELECT * FROM seUser WHERE ID_User = '1'
     SELECT * FROM seUser WHERE ID_User = '23'

... and a view with the two options ...

  

SELECT * FROM seUser WHERE ID_User = '1' OR ID_User = '23'

    
answered by 06.07.2017 в 00:33