I have two tables:

table1:
----------------------
id     	name	member
----------------------
1	user1
2	user2
3	user3
table2:
------------
id	group
1	A
1	B
2	A

Now I want to update table1 and set member field to "Y" if this userID belongs to table2, how should I write UPDATE statement? thanks for any help.

You will need a SELECT statement and an UPDATE statement.

The SELECT will be something like "SELECT DISTINCT id FROM table2". In the code, loop through all the results and in each iteration, execute "UPDATE table1 SET member='Y' WHERE id='$idFromSelectResult'".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.