1

Suppose my table is like this:

table user
id | email | password | age | gender
1 | [email protected] | password | 1 | m
2 | [email protected] | password | 2 | m

Assuming as a regular user, I know nothing about the table and its data. In a form, I enter the following emails to get their id number:

([email protected], [email protected], [email protected])

So the query would be:

select id from user where email in ([email protected], [email protected], [email protected])

should return:

(1,2)

Now, how do I figure out which id is for which user? I was thinking of querying one user at a time but if the list becomes too big, it would be bad practice.

What is a better method to implement something like this?

The reason I need to know which id belong to which user is because frontend needs to tell the user which emails didnt work etc.

1 Answer 1

2

select email,id from user where email in ('[email protected]', '[email protected]', '[email protected]') will return both the email and the id (matched up).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.