Joao Marcos Barbosa Oliveira
Posts: 0
Joined: Sat Jan 04, 2014 2:30 pm

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

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)

Return to “Issues”