Solved

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

Posted on 2009-06-28
5
671 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

0
Comment
Question by:jbpeake
  • 2
  • 2
5 Comments
 
LVL 28

Accepted Solution

by:
gamebits earned 500 total points
ID: 24732005
You are trying to do a subquery in the same table than the query, not sure what you are trying to achieve, would this not be working

$data = mysql_query("SELECT * FROM users WHERE state_id = '".$session_state_id."' ORDER BY '$sorter' ASC");
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24732010
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

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24732012
of course, gamebits's query code is more efficient, anyhow :)
0
 

Author Comment

by:jbpeake
ID: 24732339
Ughh... painfully obvious when I see what you done.  Thanks.
0
 
LVL 28

Expert Comment

by:gamebits
ID: 24732386
" painfully obvious " believe me I know the feeling, thanks for the points and the grade.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question