Page 1 of 1

Is it possible to use a select statement inside the where clause?

Posted: Tue Jan 21, 2014 2:22 am
by Joao Marcos Barbosa Oliveira

Hi,

Is it possible to use a select statement inside the where clause?

I have two tables:

  • users

  • profiles

    Each profile contains a field called userid (which links the profile to the user).

    Lets say I want to retrieve the profile of a user using the user's username:

    theuserid = SELECT userid FROM users WHERE username=theusername
    profile = SELECT [...] FROM profiles WHERE userid=theuserid

    How could I combine these two commands into one command (so that I only have to query the database once from my code)?

    Is this possible?

    SELECT [...] FROM profiles WHERE (SELECT userid FROM users WHERE username=theusername)


Is it possible to use a select statement inside the where clause?

Posted: Tue Jan 21, 2014 2:29 am
by Illya Stepanov

Hi -

Have you looked here - http://docs.appery.io/documentation/b...