2016-12-26 110 views
-5

亲爱的朋友,我无法理解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。它的运行如何。

+0

MySQL正在从右向左读 – brianforan

+0

谢谢您的回答,但如果当我写一个查询“SELECT * FROM其中id ='123'和名称像'as%'或名称像'%as'“它给所有id的结果,不仅id = 123它显示所有id – user3666505

+0

其中你问的问题是不同于你的打算问。 – Strawberry

回答

0

该查询说:

选择所有从持有一个名为“示例表”的表中有一个特定的数据库中的行,其中名称等于“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'" 

这就是为什么你得到合并的wherelike

+0

请查看我对上面的评论 – user3666505

+0

重新编辑:你解析错误的查询:)它做了别的。 –

+0

你想提一下错误吗? @SergioTulentsev –

-1

结果在你上面的查询SELECT语句将首先被执行select * from tablename后病情会被执行Where条款并在Where子句中执行从左至右where name='123'name将该值与name='123'进行比较。

0

您正试图创建一个结果集 它在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]