0

I want to write a Login authentication query,

I want to check user Login and password if that is found in my database i fetch his details however if i cant find exact details i want to check if only the provided username exist in the table and get his name and profile pic.

i can do some thing like ..

SELCT * FROM `use_table` WHERE `username` = 'something' AND `password` = 'something'

if the above query returns empty rows then i fire another query

SELCT `name`, `profile_pic` FROM `use_table` WHERE `username` = 'something'

I can do this using multiple queries but the tricky part is i want to do this using a single query. ANY HELP ??

2 Answers 2

0

Use NOT IN:

SELECT `name`, `profile_pic` 
FROM `use_table` 
WHERE `username` = 'something' 
AND NOT IN (
    SELECT * FROM `use_table`
    WHERE `username` = 'something' AND `password` = 'something'
)
Sign up to request clarification or add additional context in comments.

1 Comment

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( SELECT * FROM
0

quit easy, you just use the second query, but with password return like this:

SELCT `name`, `profile_pic`,`password` FROM `use_table` WHERE `username` = 'something'

Then you do a compare with user input password and password that retured

if they matches, then login ok, else login failed! but you also get the user's information!

1 Comment

i thought about it .. and its a good idea but still i want to know if it is possible using a single query

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.