1

I want to get a boolean output to a mysql query.

i issue a query like the following

EXISTS (
    select 1 
    from someothertable 
    where someaccid = (
       select someid 
       from smtable 
       where username = 'someuser' 
       and password = 'somepassword')
)

This returns an error 1064 in the mysql shell and returns a bool false in php mysqli .

How can i get an output as bool using EXISTS command?

Thanks in advance.

1 Answer 1

13

Use SELECT:

SELECT EXISTS (select 1 
               from someothertable 
               where someaccid = (select someid 
                                  from smtable 
                                  where username = 'someuser' and 
                                        password = 'somepassword'))

This will return 1 if EXISTS is successful, 0 otherwise.

Sign up to request clarification or add additional context in comments.

Comments

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.