简体   繁体   中英

Can you select and join in one mysql query?

Is it possible to SELECT a column from a row in mysql and then update some other column in that row without doing two queries? As of now, I am selecting from a table and then updating a column from the same row I selected with two separate queries

Principally, if the SQL statement starts with "UPDATE ..." it may modify data, but doesn't return any record set. And if it starts with "SELECT ..." it returns records but does not have modifying side effects. This is even true with sub-queries as you cannot use UPDATE in a subquery.

All this also has to do with a structured separationof access rights (eg a user with only SELECT right should not be able to modify data).

不确定有关mysql的信息,但sql server允许您使用“ select statment>”中的update'table'set'asignation'[,'asignation']

UPDATE vendors ven1 SET ven1.parent_name = ven2.vendor_name FROM

 vendors ven2 

where ven1.parent_id = ven2.ID

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