mercredi 4 novembre 2015

Update column based on if a join exists - SQLITE

I can't seem to get this working in SQLITE.

I'm trying to add a 1 if a matching join exists for a row or a 0 if not.

I thought the code would add a 1 to those matching rows but instead it just adds a 1 to everything irregardless of a match:

update tbl1
SET has_data = 1
where exists(
    SELECT *
    FROM tbl1
    join tbl2 on tbl2.r_num = tbl1.r_num
)

I've seen some examples of 'case's that I couldn't figure how to write either that may be useful in this situation for applying a 0 or 1?

Thanks for any help!

Aucun commentaire:

Enregistrer un commentaire