SQL join left join 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. bKjia. c0m
3 wenti
The join left join query result is as follows:
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 ';
$ Sql2 = 'select. studentid,. workid, B. workname,. store from a join B on. workid = B. workid where. studentid = 1 select. studentid,. workid, B. workname,. store from a join B on. workid = B. workid where. studentid = 2 ';
// Database tutorial connection
$ 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];
}
/*
The result is www. bKjia. c0m.
StudentID workID workName store
1 1 zuoye 98
1 2 www. bKjia. c0m 95
*/
$ Query = mysql_query ($ sql1 );
While ($ rs = mysql_fetch_array ($ query ))
{
Echo $ rs [0], $ rs [1], $ rs [2];
}
/*
Result:
StudentID workID workName store
2 1 zuoye 98
2 3 wenti 80