什么第一次运行mysql查询
问题描述:
亲爱的朋友,我无法理解mysql查询从哪里。什么第一次运行mysql查询
select * from `tablename` where name='123'
在这个查询中哪个节运行第一个select或where。 并在where子句中如何从左到右或从右到左运行mysql。
在查询
"select * from where id='123' and name like 'as%' or name like '% as'"
所有的ID给予其结果,不仅ID = 123。它的运行如何。
答
该查询说:
选择所有从持有一个名为“示例表”的表中有一个特定的数据库中的行,其中名称等于“123”
So, this query will fetch all the rows from the table where it encounters name as "123"
注意:上述查询中的名称是表格中的一列。
希望这有助于
编辑
由于OP修改问题的解释去为:
当在查询,如果LIKE
条款与WHERE
子句中使用则查询变得像:
This
"select * from table where id='123' and name like 'as%' or name like '% as'"
将变为:
"select * from table where id='123' UNION select * from table where name like 'as%' or name like '% as'"
这就是为什么你得到合并的where
和like
答
结果在你上面的查询SELECT语句将首先被执行select * from tablename
后病情会被执行Where
条款并在Where
子句中执行从左至右where name='123'
列name
将该值与name='123'
进行比较。
答
您正试图创建一个结果集 它在3个阶段执行:
1. FROM table-name // Scan all the tuples [rows] in this table
2. WHERE column-name = '123' // Extract those rows that satisfies some selection criteria, and ignore the rest
3. SELECT * // Include ALL the columns in the tuple in the result set [Asterisk is like a wild-card]
MySQL正在从右向左读 – brianforan
谢谢您的回答,但如果当我写一个查询“SELECT * FROM其中id ='123'和名称像'as%'或名称像'%as'“它给所有id的结果,不仅id = 123它显示所有id – user3666505
其中你问的问题是不同于你的打算问。 – Strawberry