I'm a newbie at SQL and I can't manage to make the following sql query to work ! There seem to be an issue with the alias and the where clause but I don't find any workaround...
Could someone enlighten me ?
Table t_adresse (SCHEMA ab)
-------
ad_nomvoie | ad_numero | action |
Privet Drive 4
KameHouse St 12
Table t_adresse (SCHEMA poma)
-------
ad_nomvoie | ad_numero |
Privet Drive 8
KameHouse St 12
After my update I would like to get this result below (if I had to run the select "defined" by "req1") :
-------
ad_nomvoie (from ab) | ad_numero (from ab) | ad_nomvoie (from poma) | ad_numero (from poma) | action
Privet Drive 4 Privet Drive 8 M
KameHouse St 12 KameHouse St 12
.
WITH req1 as (SELECT AA.ad_nomvoie, AA.ad_numero, BB.ad_nomvoie, BB.ad_numero, AA.action
FROM ab.t_adresse as AA
INNER JOIN poma.t_adresse as BB
ON AA.ad_code = BB.ad_code
ORDER BY AA.ad_numero ASC)
UPDATE ab.t_adresse
SET "action" = 'M'
FROM req1
WHERE AA.ad_nomvoie = BB.ad_nomvoie
AND AA.ad_numero == BB.ad_numero