0

I dunno how do I need to solve it:

i've got a select statement:

SELECT 
       sum_lines.id, 
       sum_lines.line_id, 
       sum_lines.summary_id, 
       sum_lines.text_content, 
       sum_tbl.user_id 
FROM 
       sum_lines 
JOIN 
       sum_tbl 
ON 
       sum_lines.summary_id = sum_tbl.id 
WHERE 
       sum_tbl.user_id = 1 

how can I delete everything that this statement is showing with a delete statement?

1

2 Answers 2

4

If you want to delete from both tables you need two deletes:

delete sum_lines
from sum_lines
join sum_tbl on sum_lines.summary_id = sum_tbl.id where sum_tbl.user_id = 1

delete from sum_tbl 
where sum_tbl.user_id = 1

Just make sure to do a backup before you delete something. It can easily be done with something like this:

select *
into sum_lines_backup
from sum_lines

select *
into sum_tbl_backup
from sum_tbl
Sign up to request clarification or add additional context in comments.

1 Comment

My bad, i have updated the answer. You need to specify the table to delete from directly after the "delete" statement.
0

Try This:

delete sum_lines from sum_lines as a

join sum_tbl as b on b.id = a.id 

where b.user_id = 1

Make sure the column name sum_lines[id] data must match with sum_tbl[id], otherwise it wont work. Maybe sum_lines.summary_id = sum_tbl.id is not match data on your database.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.