Link to home
Start Free TrialLog in
Avatar of jbpeake
jbpeake

asked on

SQL query error: Operand should contain 1 column(s)

When I run the sql query below I get an error that says "Operand should contain 1 column(s)"  It is probably something simple I'm new to trying to write two statements together.  Any thoughts?
$data = mysql_query("SELECT username, first_name, last_name, middle_name FROM users WHERE username IN (SELECT * FROM users WHERE state_id=".$session_state_id.") ORDER BY ".$sorter." ASC")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gamebits
gamebits
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
IN ( SELECT * ...)
is wrong, as SELECT * returns multiple columns.
this would work better:
$data = mysql_query("SELECT username, first_name, last_name, middle_name FROM users WHERE username IN (SELECT username  FROM users WHERE state_id=".$session_state_id.") ORDER BY ".$sorter." ASC");

Open in new window

of course, gamebits's query code is more efficient, anyhow :)
Avatar of jbpeake
jbpeake

ASKER

Ughh... painfully obvious when I see what you done.  Thanks.
" painfully obvious " believe me I know the feeling, thanks for the points and the grade.