Trouble with select statement that combines 2 columns from 2 tables
Hello,
very new to MYSQL. Having trouble with select statement that combines 2 columns from 2 tables (summing column2 for all similar states in column1).
1st table = tracker
column1 = state
column2 = data
example below:
state data
TX 1000
----------------------------
2nd table = precaution
column1 = state
column2 = data
example below:
state data
TX 100
LA 10000
---------------------------
Result should be:
state datap
TX 1100
LA 10000
I'm hung up on the following select statement (close but no cigar) :(
Code:
SELECT distinct tracker.state, sum(tracker.data) datap From tracker group by state Union select distinct precaution.state, sum(precaution.data) datap From precaution group by state
Result of code above does not combine similar states and their related data
Any help would be appreciated.
Thanks,
JB
Trouble with select statement that combines 2 columns from 2 tables
Hi sniperman,
VERY new to MYSQL.....you might try below to see if it works.
Code:
$strQuery = "SELECT users.username, users.password, objects.obj1, objects.obj2 FROM users INNER JOIN ruler ON users.user_id = objects.user_id";
$result = mysql_query($strQuery) or die(mysql_error());
JB