I got two tables which works the same way as a customer and the transactions that it made.
So one customer can have more than one transactions. And so when I delete the customer, I want to delete all the transactions that he has made.
Below is my 'customer' table where its has a uuid as the PRIMARY KEY
Below is the 'transaction' table where the column bird_id is refered to the uuid column of the above table.
I have tried this.
WITH delete_bird_and_entry AS (
select birdsdata.id from birdsdata
LEFT JOIN
entries ON birdsdata.name = entries.bird_name and birdsdata.species = entries.species_name
where birdsdata.id = '6ca574a7-b515-4629-8aa6-4149fcef2bd8'
)
DELETE from birdsdata, entries where id IN (select id from delete_bird_and_entry);
But its not working as it gives me a syntax error.
ERROR: syntax error at or near ","
LINE 8: DELETE from birdsdata, entries where id IN (select id from d...
Hope my question was clear. This is my first time dealing with postresql so not sure as to how to ask the question. Thank you in advance!


ON DELETE CASCADE