Solved

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

Posted on 2009-06-28
5
674 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

689 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