user2447290
user2447290

Reputation:

How can I insert/update with a related table?

I have these three tables:

You should also do that if the key exists then update. Then the only values are known as:

The table has to be isplaying to update or insert.

User.ID_Facebook = 2131234

Game.Name="Name of the game"

IsPlaying.Time_UP="0000-00-00 00:00:00"

Example SQL (Doesn't work)

INSERT INTO isplaying (ID_User, ID_Game, Time_UP)

VALUES((SELECT ID FROM User WHERE ID_FACEBOOK=2131234), (SELECT ID FROM Game WHERE Name="Name of the game"), "2016-05-18 00:00:00")

ON DUPLICATE KEY UPDATE ID_Game=, Time_UP="2016-05-18 00:00:00"

Upvotes: 1

Views: 33

Answers (1)

user2447290
user2447290

Reputation:

INSERT INTO isplaying (ID_User, ID_Game, Time_UP) 

VALUES((SELECT ID From user WHERE ID_Facebook=2131234),(SELECT ID From game WHERE name="NAME OF GAME"), "2016-00-00 00:00:00") 

ON DUPLICATE KEY UPDATE ID_Game=(SELECT ID From game WHERE Name="NAME OF GAME"), Time_UP="2016-00-00 00:00:00"

Upvotes: 1

Related Questions