MSSQL Multi SELECT FROM 4表(怎么样?)

时间:2012-12-07 06:04:41

标签: php sql-server-2008

当我提取aasoc时,我需要从其他表中选择4。它非常糟糕和停止的驱动页面(。 请告诉我,是否可以提出一个请求而不是四个?

$sql_id_city = "SELECT * FROM City WHERE id_city='$id_city'";
$get_id_city = sqlsrv_query($conn, $sql_id_city);
$info_id_city = sqlsrv_fetch_array($get_id_city, SQLSRV_FETCH_ASSOC); 
$name_city=$info_id_city['name'];


$id_producer_country=($i['id_producer_country']!='')? $i['id_producer_country']:'0';

$sql_id_producer_country = "SELECT * FROM Producer_country WHERE id_producer_country='$id_producer_country'";
$get_id_producer_country = sqlsrv_query($conn, $sql_id_producer_country);
$info_producer_country = sqlsrv_fetch_array($get_id_producer_country, SQLSRV_FETCH_ASSOC);
$name_producer_country=$info_producer_country['name'];



$id_firm=($i['id_firm']!='')? $i['id_firm']:'0';

$sql_id_firm = "SELECT * FROM Firm WHERE id_firm='$id_firm'";
$get_id_firm = sqlsrv_query($conn, $sql_id_firm);
$info_film = sqlsrv_fetch_array($get_id_firm, SQLSRV_FETCH_ASSOC);
$name_firm=$info_film['name'];
$phone_firm=$info_film['phone'];

$id_price=($i['id_price']!='')? $i['id_price']:'0';

$sql_id_cost = "SELECT * FROM Cost WHERE id_price='$id_price'";
$get_id_cost = sqlsrv_query($conn, $sql_id_cost);
$info_cost = sqlsrv_fetch_array($get_id_cost, SQLSRV_FETCH_ASSOC);
$cost=$info_cost['cost'];
$id_currency=$info_cost['id_currency'];
$id_sale=$info_cost['id_sale'];

1 个答案:

答案 0 :(得分:0)

    "SELECT * FROM City , Producer_country , Firm , Cost WHERE City.id_city='$id_city'
 AND Producer_country.id_producer_country=City.'$id_producer_country(country id as field in city table)' 
AND Firm.id_firm='$id_firm(fiels name as u in Producer_country table )' AND
 Cost.id_price='$id_price(fiels name as u in firm table)'"


if u have same as fiels in other table so u can use the as keyword for avoid the ambiguity