SQL Join left federated Associated Query instance tutorial
Table A: Results and data
StudentID WorkID Store
1 1 98
1 2 95
2 1 90
2 3 80
Table B: Results and data
WorkID Workname
1 Zuoye
2 www.111cn.net
3 Wenti
We're going to use join left federated query results for the following
StudentID WorkID Workname Store
1 1 Zuoye 98
1 2 Shiti 95
Or
StudentID WorkID Workname Store
2 1 Zuoye 98
2 3 Wenti 80
*/
$sql = ' Select A.studentid,a.workid,b.workname from a join B on a.workid=b.workid where a.studentid=1 ';
$sql 2 = ' Select A.studentid,a.workid,b.workname,a.store from a join B on A.workid=b.workid where a.studentid=1 select A.St Udentid,a.workid,b.workname,a.store from a join B on a.workid=b.workid where a.studentid=2 ';
Database Tutorial Connections
$db = ' fangke_cc ';
mysql tutorial _pconnect (' localhost ', ' root ', ' root ') or Die (Mysql_error ());
mysql_select_db ($DB);
mysql_query ("Set names ' GBK '");
$query = mysql_query ($sql);
while ($rs = Mysql_ Fetch_array ($query))
{
echo $rs [0], $rs [1], $rs [2];
}
/*
result is www.111cn.net< br> studentid workid workname store
1 1& nbsp; zuoye
1 2 www.111cn.net
*/
$query = mysql_query ($sql 1);
while ($rs = mysql_fetch_array ($query))
{
echo $rs [0], $rs [1], $rs [2];
}< br>/*
results for
studentID workid workname store
2 & nbsp; 1 zuoye
2 3 wenti