Hia
Hia

Reputation: 103

how to update one table using data from second table

I am bit stuck with this one.. what i want is update app_name (first table). It returns no error.. but does nothing...

UPDATE tbl_m_app AS tma, tbl_measure AS tm
SET tma.app_name='Ap1' 

WHERE (tm.mesure_id = tma.mesure_id
AND tm.live = 1)

Upvotes: 0

Views: 114

Answers (2)

Howard
Howard

Reputation: 3895

I think this SQL is fine, it's just not matching any rows.

Check this by using a select with the same where clause:

SELECT * FROM tbl_measure tm WHERE tm.live=1;

0 rows returned, right?

Upvotes: 0

zerkms
zerkms

Reputation: 254886

This query will do the same work in more obvious way and without joins

UPDATE tbl_m_app AS tma
SET tma.app_name='Ap1'
WHERE tma.mesure_id IN (SELECT tm.mesure_id FROM tbl_measure AS tm WHERE tm.live = 1)

Upvotes: 1

Related Questions