View Full Version : How to do this effect
01-21-2010, 06:10 PM
$sql=mysql_query("select * from abc WHERE name='laal'");
mysql_query("SELECT * from cde WHERE id='$id'");
how to combine these two query together to become one query
01-21-2010, 06:23 PM
No idea what your tables look like... whether `name` is unique, etc. There are multiple options.
WHERE `id` = (
WHERE `name` = 'laal'
LEFT JOIN `abc`
ON `abc`.`id` = `cde`.`id`
WHERE `abc`.`name` = 'laal'
01-21-2010, 06:46 PM
left join? table cde have 2 records which are same id, which means the id from abc will be used to select two recrods from table cde, i think left join cannot produce this outcome right?
01-21-2010, 06:50 PM
I think it would.
The sub query won't work for you? It is technically still two queries but will result in less code.
The left join is what you're looking for. It will return all matching rows from `cde` where `cde`.`id` = `abc`.`id` and `abc`.`name` = laal
01-21-2010, 06:57 PM
please help me again. Let me give you the table structure
cid name quality
1 laal 3
2 gaga 4
id cid subname
1 1 baba
2 1 sasa
3 2 tata
the cid in table cde is same as cid in table abc
now i want to ge4t something like structure below
cid name subname quality
1 laal (baba,sasa) 3
2 gaga (tata) 4
how can i do this?
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.