Home > Database > Mysql Tutorial > body text

mysql-MySQL联接查询到的显示结果

WBOY
Release: 2016-06-06 09:41:47
Original
1174 people have browsed it

mysqlselect联接查询数据库

表:fruits的字段f_id为primary key
图片说明
表:suppliers的字段s_id为primary key与fruits的s_id有相同的数据类型
图片说明
然后使用这2句查询语句:
1、select suppliers.s_id,s_name,f_name,f_price from suppliers inner join fruits on suppliers.s_id=fruits.s_id;
查询的都结果如下:
图片说明
2、select suppliers.s_id,s_name,f_name,f_price from fruits inner join suppliers on fruits.s_id=suppliers.s_id;
查询到的结果如下:
图片说明

可以确定的是查询的结果肯定是一样的,但是问题是使用第一句查询语句的条件是suppliers.s_id=fruit.s_id,我的理解是,当我们连接两张检索数据的时候,检索的方式是首先逐行扫描suppliers表中s_id的记录,只有条件suppliers.s_id=fruit.s_id匹配,结果才会被检索出来,所以首先要从表suppliers的s_id匹配表fruits的s_id的相等项,按道理说第一句查询语句查询到的结果应该是按照表suppliers的s_id顺序显示,为什么两个查询语句的显示结果的都是按照friuts本身的s_id的排列顺序?

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!