简体   繁体   中英

What's the difference between MySQL query

When I manually update a database in phpMyAdmin this is the code it uses:

UPDATE  `test`.`users` SET  `number` =  '12' WHERE  `users`.`id` =1;

This is the code I normally use in php when I write queries manually:

UPDATE `users` SET  `number` =  '12' WHERE `id` =1;

What is the difference? More importantly, which is better to use and why? Please answer the why, Thank You.

The one phpMyAdmin just includes the database name as well as the table name.

In PHP, this is generally not needed, because you specify the database using mysqli_select_db or mysqli_connect .

Both are equivalent; the only difference is the way the database is selected. In the first one, the database is specified explicitly in the query, in the second one, the database name is implied, since you specify it with mysqli_select_db or mysqli_connect .

phpMyAdmin使用的是它添加了数据库的名称,这通常在我们的常规练习中没有使用,但是当我们有多个数据库要连接并且在这些数据库中具有相同的表名时,这是非常好的主意。

For easy explanation,

on your first statement you just include an alias on part of table and fields to be display

and for the second was the vice versa of your first statement

but I refer to use the first statement, because when you had multiple join comes-up to your query it will be difficult to read so we need to use alias and it is a best practice for this

but when your just querying a single table its nice the second query statement

I hope it helps you,

Joven

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM