MySQL Forums
Forum List  »  Newbie

Sub-request with multiple result as condition
Posted by: Alx J
Date: March 11, 2010 08:10PM

Hi all

First, sorry for my bad ortograph, i'm french! (Thats my parent fault ...:P)

For a php/ajax webApp i try too make a sub-query on multiple result
Exemple:

My_table:
<table>
id varName varValue ident
___________________________
1 name John q001
2 name Jean q002
3 city Quebec q001
4 contry Canada q001
</table>

My query (of course not working..)

<NOT WORKING SQl QUERY>
SELECT * from my_table where `varName`= 'city' AND `varValue` = 'Quebec' AND
(SELECT ident from my_table where `varName` = 'name' AND `varValue` LIKE '%J%');
</NOT WORKING SQl QUERY>

I'm not sure if subquery is the good way, maybe other way like store procedure or UNION or JOINT is the good way. I'm not strong enough in SQL to know the good way...

Of course with a simple php scrip like this one bellow i can do the job but with 20000 result my AJAX request gonna be slow. I think a great sql query have better performance.

<PHP SCRIPT>
$query = exec_query(SELECT ident from my_table where `varName` = 'name' AND `varValue` LIKE '%J%')
for ($i;$i<$numRow;$i++){
$query2 = (SELECT * from my_table where `varName`= 'city' AND `varValue` = 'Quebec' AND ident = $query[$i]['ident']);
}

</PHP SCRIPT>

Does my explanation are clear? not sure .. hehe

Anyway, thank your help

***CONFIG: MYSQL 5.0.51a On debian Lenny, Query with MySQL Administrator 1.2.16 Windows**

Options: ReplyQuote


Subject
Written By
Posted
Sub-request with multiple result as condition
March 11, 2010 08:10PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.