We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

jbpeake
jbpeake asked
on
Medium Priority
709 Views
Last Modified: 2012-05-07
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

Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
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

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

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

Author

Commented:
Ughh... painfully obvious when I see what you done.  Thanks.
CERTIFIED EXPERT

Commented:
" painfully obvious " believe me I know the feeling, thanks for the points and the grade.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.