盾怪网教程:是一个免费提供流行杀毒软件教程、在线学习分享的学习平台!

Mysql Join的使用图文说明教程

时间:2025/3/7作者:未知来源:盾怪网教程人气:

[摘要]+-------------+-----------------+----------------+2 rows in set (0.01 sec)mysql>在PHP脚本中使用JOINPHP...
+-------------+-----------------+----------------+2 rows in set (0.01 sec)mysql>

在PHP脚本中使用JOIN

PHP 中使用mysql_query()函数来执行SQL语句,你可以使用以上的相同的SQL语句作为mysql_query()函数的参数。

尝试如下实例:

<?php$dbhost = 'localhost:3036';$dbuser = 'root';$dbpass = 'rootpassword';$conn = mysql_connect($dbhost, $dbuser, $dbpass);if(! $conn ){  die('Could not connect: ' . mysql_error());}$sql = 'SELECT a.tutorial_id, a.tutorial_author, b.tutorial_count        FROM tutorials_tbl a, tcount_tbl b        WHERE a.tutorial_author = b.tutorial_author';mysql_select_db('TUTORIALS');$retval = mysql_query( $sql, $conn );if(! $retval ){  die('Could not get data: ' . mysql_error());}while($row = mysql_fetch_array($retval, MYSQL_ASSOC)){    echo "Author:{$row['tutorial_author']}  <br> ".         "Count: {$row['tutorial_count']} <br> ".         "Tutorial ID: {$row['tutorial_id']} <br> ".         "--------------------------------<br>";} echo "Fetched data successfully\n";mysql_close($conn);?>

MySQL LEFT JOIN

MySQL left join 与 join 有所不同。 MySQL LEFT JOIN 会读取左边数据表的全部数据,即便右边表无对应数据。

实例

尝试以下实例,理解MySQL LEFT JOIN的应用:
root@host# mysql -u root -p password;Enter password:*******mysql> use TUTORIALS;Database changedmysql> SELECT a.tutorial_id, a.tutorial_author, b.tutorial_count    -> FROM tutorials_tbl a LEFT JOIN tcount_tbl b    -> ON a.tutorial_author = b.tutorial_author;+-------------+-----------------+----------------+

关键词:Mysql Join的运用图文详细教程




Copyright © 2012-2018 盾怪网教程(http://www.dunguai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版