This question already has answers here:
MySQL, update multiple tables with one query
(7 answers)
Closed 4 years ago.
I have to pass a mysqli update query. Following are the three different tables with the situation.
I have a user_table with columns
user_id
user_email
I have a webpage_table with columns
webpage_id
first_webpage
second_webpage
I have a user_data_table with only columns
user_id
webpage_id as foreign key
Now I have to update the values of webpage_table where the user_email="johndoe#xyz.com"....
What will be my update mysqli_query() for the above situation...I tried but i'm not able to go any further of where condition.... Below is my attempt
UPDATE `webpage_table` SET `first_webpage`='xyz', `second_webpage`='xyz'
WHERE
You could use an updated based on join
with the related table
UPDATE `webpage_table`
INNER JOIN user_data_table d on u.user_id = d.user_id
and `webpage_table`.webpage_id = d.webpage_id
INNER JOIN user_table u.user_email="johndoe#xyz.com"
SET `first_webpage`='xyz',
`second_webpage`='xyz'
Related
This question already has an answer here:
Insert into one table base on join result from 2 other table
(1 answer)
Closed 3 years ago.
I have an account and customer tables which can be linked by customer col and get the date col to the account table.
account table:
customer table:
final table:
If I use the below query, I am getting following error
ERROR: more than one row returned by a subquery used as an expression
What am I doing wrong?
UPDATE account
SET date = (
SELECT date
FROM customer
WHERE customer.customer = account.customer
);
Consider the update ... join ... set syntax:
update account a
inner join customer c on a.customer = c.custom
set a.date = c.date
This question already has answers here:
How can I do three table JOINs in an UPDATE query?
(7 answers)
Closed 3 years ago.
I have got an error in running this query in phpMyadmin. The query is to update a table using inner join .Pls help me
My tables are :
userpswd
ID
password
Name
Col 4
Col 5
index
oncampus_present ( the colum I want to update )
oncampus
index
ID
I already have gone through most of the threads given here regarding the same and none seem to work.
UPDATE userpswd
SET oncampus_present='yes'
FROM userpswd
INNER JOIN oncampus
ON userpswd.ID=oncampus.ID
WHERE userpswd.oncampus_present=NULL
You have an error in your SQL syntax
Try This
UPDATE userpswd
INNER JOIN oncampus
ON userpswd.ID=oncampus.ID
SET oncampus_present='yes'
WHERE userpswd.oncampus_present IS NULL
This question already has answers here:
MySQL Error 1093 - Can't specify target table for update in FROM clause
(16 answers)
Closed 4 years ago.
I've created a new column (third one) and all records are null in that column. The table has 100 rows. When I try INSERT INTO, records are added but only from 101 row and previous ones are still null. That's why I decided to use UPDATE, but I have the next error message: You can't specify target table 'actors' for update in FROM clause
Here is my query:
UPDATE
actors
SET
starred_count = (
SELECT COUNT(actors.Actor_id)
FROM starred
INNER JOIN actors ON actors.Actor_id = starred.Actor_id
GROUP BY starred.Actor_id
ORDER BY starred.Actor_id
)
How could I do this properly?
Give a try to next query, since on MySQL updating using a query is not valid.
UPDATE
actors AS a
INNER JOIN
(SELECT Actor_id, COUNT(*) AS starred_count
FROM starred
GROUP BY Actor_id) AS s ON s.Actor_id = a.Actor_id
SET
a.starred_count = s.starred_count
This question already has answers here:
SQL query return data from multiple tables
(6 answers)
Closed 6 years ago.
I want to take all the data from two tables with the same user_id, but I don't know what type of join to use and I want to be sure with the syntax of the query.
"users" table:
"schedule" table:
Here's a simple LEFT JOIN example:
SELECT * FROM `users` LEFT JOIN `schedule` ON `users`.`userid` = `schedule`.`user_id`
WHERE `users`.`userid` = ?
this will collect everything from both tables and then you can output it accordingly.
This question already has answers here:
String concatenation in MySQL
(5 answers)
Closed 6 years ago.
I added a column to my WorkSheetTransaction table and want to populate it with a name built from the Department table. Both tables are already populated with the join field DepartmentId.
The following query runs ok but no rows are updated. Why not?
update WorkSheetTransactions
inner join Departments on WorkSheetTransactions.DepartmentId = Departments.DepartmentId
set WorkSheetTransactions.DepartmentName = (Departments.GL_Account + '-' + Departments.DepartmentName)
I've tried many variations but I just can't see where I've gone wrong. BTW, the join field is an integer in both tables and all the other 2 fields are var_chars.
In mysql, you should use concat to concatenate strings:
UPDATE WorkSheetTransactions
INNER JOIN Departments
ON WorkSheetTransactions.DepartmentId = Departments.DepartmentId
SET WorkSheetTransactions.DepartmentName = concat(Departments.GL_Account, '-', Departments.DepartmentName)