mysql subquery help... again
Posted: Thu Jul 10, 2008 3:20 am
I think this is possible to do at the database level in one query instead of using PHP to loop and create thousands of queries. I seem to be having lots of problems with this lately.
OK, here's the scenario. I have two tables. The first is a standard members table with `id`, `last_logged_in`, and `member_type` fields among others.
The second table contains the same 3 fields I mentioned specifically above. However, this table is only updated once per week on a crontab script.
So, I would like to update the second table using ONE query with the respective data from the first tables.
Here's my pathetic attempts
Error: More than one row returned in subquery
Error: Syntax error near 'GROUP BY'
OK, here's the scenario. I have two tables. The first is a standard members table with `id`, `last_logged_in`, and `member_type` fields among others.
The second table contains the same 3 fields I mentioned specifically above. However, this table is only updated once per week on a crontab script.
So, I would like to update the second table using ONE query with the respective data from the first tables.
Here's my pathetic attempts
Code: Select all
UPDATE `table_two` SET `last_logged_in` = (SELECT `last_logged_in` FROM `table_one`)Code: Select all
UPDATE `table_two` SET `last_logged_in` = (SELECT `last_logged_in` FROM `table_one`) GROUP BY `member_id`