I’m a beginner in sql and I am doing this through a php document. I need to know how to combine these into one query. The sql is rough but hopefully you all should get the idea of what I’m trying to do.
**What I’m trying to do is join the ‘username’ in the ‘stats’ and ‘ufc133’ tables
then update the ‘scores’ table based on the value stored in ‘pick1’ from the ‘ufc133’ table
This is code for a sports picks website and my goal with this query is to give users scores based on the right or wrong picks they make. The scores and picks are stored in different tables. This particular query is just for ‘pick1’
The Code:
<?php
mysql_query("
SELECT * FROM ufc133, stats JOIN stats ON ufc133.username = stats.username
UPDATE stats SET score = (score + 10), mmascore = (mmascore + 10), mmawins = (mmawins + 1), mmagames = (mmagames + 1), wins = (wins + 1), games = (games + 1)
WHERE pick1 = 11
");
?>
Updates statements can only reference one table. Your update can contain a subselect in the WHERE clause to match the ID of the rows you want to update with the result of some query. For example: