Home » Performance » FullText » subquery returns more than one row.
subquery returns more than one row. [message #4462] Tue, 16 June 2009 17:09 Go to next message
charanv  is currently offline charanv
Messages: 6
Registered: March 2009
Junior Member
Hi Thankx in advance.

I am currently working on a query that would look something like below:

There are two tables t1 and t2 and these are the columns in each table
t1: sid, storename
t2. storeID, storename, keywords

Here is the query
$sql = mysql_query("select t1.sid from t1,t2 where (t1.sid = t2.storeID and t2.storeID = (select t2.storeID from t2 where t2.storeID like '%autos%'))");

There error I get is subquery returns more than one results. That is eaxclty how I want it to run.. I have a query which pulls out couple of results I want to use these results to pull out other results from another table.

If I break up the query here is how I can write
####################################
METHOD2:
$s1 = mysql_query("select t2.storeID from t2 where t2.keywords like 'auto'");
while ($row = mysql_fetch_array($s1))
{
$id = $row['storeID'];
$query_2 = mysql_quert("select t1.sid from t1 where t1.sid = '$id'");
while ($row1 = mysql_fetch_array($query_2))
{
echo $row1['sid'];
}
}

###################################

I do not want to use this method 2 where I need to write while loops. I want to know if there is a way I can write the two seperate queries as one in mysql and execute it....

Thank you
Charan

[Updated on: Tue, 16 June 2009 17:10]

Re: subquery returns more than one row. [message #4469 is a reply to message #4462 ] Sun, 21 June 2009 13:04 Go to previous message
januzi  is currently offline januzi
Messages: 116
Registered: December 2008
Senior Member
select t1.sid from t1
left join t2 on t1.sid = t2.storeID
where t2.keywords like '%autos%'
group by t1.sid

Something like that ?
Previous Topic:Using Group by in Full text search
Next Topic:Query with match against another table field...
Goto Forum:
  


Current Time: Fri Jul 30 05:39:58 EDT 2010

Total time taken to generate the page: 0.01354 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7.
Copyright ©2001-2007 FUD Forum Bulletin Board Software

MySQL is a trademark of Sun Microsystems.
InnoDB is a trademark of Oracle Corp.

Percona Performance Forums are a service of Percona, Inc.
Not affiliated with Sun Microsystems or Oracle Corp.