mysql - Update a field thanks to a subquery based on another field -


I use a MySQL DB, and I want to update a field based on another table. Something like this:

Table 1 set field 1 = Table 2. Id where in field 2 (table 2 to table 2. Select name);

I know this query will not work, but here's the idea. Is this also possible?

You can use a correlated sub query as the following: Match value will be refunded This will increase an error if more than one matching value is returned or the zero is returned, the field is canceled. If that last action is not desirable, you will need the where section.

  Update Table 1 SET Field 1 = (Select Table 2. 2. From the table table table 2. Where table 2. Zone column = Table 1. Join column)  
< P> Edit

With a record of 0 or more than 1 match you can

  SELECT table1.JoinColumn, COUNT (DISTINCT table2.ValueColumn ) Include Table 1 in Left 2 Table 2 on Table 2 Join column = Table 1. Table 1 through Zone column group. Zone column hosting COUNT (DISTINCT table2.ValueColumn) & lt; & Gt; 1  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -