John Davidson

php - Updating a row in a table while selecting another row from another table to show where to update

0 comments
Message:


I have the tables:


__ Members __
ID(int) auto_increment
Email varchar(255) not null

__Options__
ID(int) auto_increment
FORMATION(int) not null

And I need to build a SQL request where I can update the row Options.Formation = 1 where my row Options.ID = Members.ID using the Email to identify which user is selected.


Does anyone have a clue?
I searched on internet but nothing wants to work... :(



My Answer:
You can achieve this by using a JOIN in your SQL query. Here is an example query that should work for your scenario:

sql
UPDATE Options
JOIN Members ON Options.ID = Members.ID
SET Options.FORMATION = 1
WHERE Members.Email = 'example@email.com';


In this query, we are updating the Options table and joining it with the Members table on the condition Options.ID = Members.ID. We then set the value of Options.FORMATION to 1 where the Email in the Members table matches the specified email address.

Make sure to replace 'example@email.com' with the actual email address you want to use for the update.

Rate this post

4 of 5 based on 5753 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us