0
Guys, I’m getting started on SQL and I’m having a hard time making a deletion using subquery and Join.
I created a temporary table EVENT_ITEM_PLACE_DYN_FIELD_BKP
with 7000 rows, I need to delete some table records EVENT_ITEM_PLACE_DYN_FIELD
, but I can only delete the table records EVENT_ITEM_PLACE_DYN_FIELD
provided that they exist in the table EVENT_ITEM_PLACE_DYN_FIELD_BKP
, or I used the command EXISTS
for this.
But I am having problems, because my query is bringing more than 7000 lines. I need my query to bring the same amount of rows as the temporary table. Follow the query I’m using:
Select distinct p.EVENT_ITEM_ID
From EVENT_ITEM_PLACE_DYN_FIELD p
Inner Join EVENT_ITEM_PLACE_DYN_FIELD_BKP t
On t.EVENT_ITEM_ID = p.EVENT_ITEM_ID
Where Exists (Select t.EVENT_ITEM_ID
From EVENT_ITEM_PLACE_DYN_FIELD_BKP t
Where t.DYNAMIC_FIELD_ID In (39, 40));
Table Pks EVENT_ITEM_PLACE_DYN_FIELD
:
EVENT_ITEM_ID
EVENT_PLACE_ID
COMMERCIAL_DYNAMIC_ID
DYNAMIC_FIELD_ID
LINE_NUMBER
What database are you using? And as you are starting with SQL, try to use simpler names for tables, so you don’t get lost.
– Matheus Ribeiro
I’m using PLSQL to do this.
– Leo