Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select and update table join

Status
Not open for further replies.

brownfox

Programmer
Jan 5, 2003
173
GB
I have two tables and each one has a column for usernames but only one table has a column 'status'. I want to select all the records that have matching usernames from both tables and update 'status' to 'new'. So it's a select from both tables and update in one. Can anyone help? Thanks in advance.
 
If I may clarify:
Table 1 is called 'profiles' and has two columns called 'handle' and 'status'.
Table 2 is called 'users' and has one column called 'usernames'.
I want to find all the names that are common to both tables(eg. 'handle' and 'usernames') and update 'status' to 'new'. I have tried this SQL query:
UPDATE `profiles`,`users` SET profiles.status='new' WHERE profiles.handle=users.usernames

Can anyone help?
 
That should work in version 4.04. Otherwise (i.e. if you are not on that version) you need to handle it by using a select queries and build an update query for each value.
 
Well it doesn't work. I don't know whay mySQL version I have, although I know my PHP is version 4.2.2. Could you clarify your comment: 'you need to handle it by using a select queries and build an update query for each value.'
Thanks for your time...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top