Home » SQL & PL/SQL » SQL & PL/SQL » delete statement with inner join (windows xp)
delete statement with inner join [message #499232] Mon, 14 March 2011 04:06 Go to next message
swapnabpnn
Messages: 96
Registered: December 2010
Member
Hi,
I am trying to run following sql query,but it is throwing following error.Could any one please correct the query.

SQL> delete from b$gc_count_temp a INNER JOIN COMPLEMENTS ON b$gc_count_temp.CON
NECTION_ID_TEMP=COMPLEMENTS.feature_conn_id
  2  WHERE a.current_designation is null and a.current_low is null and a.current
_high is null;

delete from b$gc_count_temp a INNER JOIN COMPLEMENTS ON b$gc_count_temp.CONNECTI
ON_ID_TEMP=COMPLEMENTS.feature_conn_id
                              *
ERROR at line 1:
ORA-00933: SQL command not properly ended



Thanks..........
Re: delete statement with inner join [message #499236 is a reply to message #499232] Mon, 14 March 2011 04:29 Go to previous messageGo to next message
Littlefoot
Messages: 21826
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Invalid syntax. Put the condition into the WHERE clause (subquery is OK), such as
delete from your_table
where id in (select some_id from another_table
             where ...
            )

Other possibilities are described in documentation.

By the way, specifying "Windows XP" would be OK if you wanted to delete something on operating system level. What is more interesting here is your database version.
Re: delete statement with inner join [message #499237 is a reply to message #499232] Mon, 14 March 2011 04:30 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
You need to correlate the tables, something akin to this

delete from emp e
where exists (select 1 
                      from dept d 
                      where e.deptno=d.deptno --correlation part
                      and d.dname='ACCOUNTING')
;
Re: delete statement with inner join [message #499239 is a reply to message #499237] Mon, 14 March 2011 04:35 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
It would help if you would provide a test case including create table and insert statements for sample data and the result that you want based on that data. You can delete from a join condition, but it needs to be within a select statement and there must be a key-preserved table. Please see the demonstration below.

SCOTT@orcl_11gR2> create table b$gc_count_temp
  2    (connection_id_temp  number primary key,
  3  	current_designation number,
  4  	current_low	    number,
  5  	current_high	    number)
  6  /

Table created.

SCOTT@orcl_11gR2> insert into b$gc_count_temp values
  2    (1, null, null, null)
  3  /

1 row created.

SCOTT@orcl_11gR2> insert into b$gc_count_temp values
  2    (2, 3, 4, 5)
  3  /

1 row created.

SCOTT@orcl_11gR2> create table complements
  2    (feature_conn_id     number primary key)
  3  /

Table created.

SCOTT@orcl_11gR2> insert into complements values (1)
  2  /

1 row created.

SCOTT@orcl_11gR2> insert into complements values (2)
  2  /

1 row created.

SCOTT@orcl_11gR2> 
SCOTT@orcl_11gR2> delete from
  2  	    (select *
  3  	     from   b$gc_count_temp a
  4  	     INNER JOIN COMPLEMENTS
  5  	     ON a.CONNECTION_ID_TEMP=COMPLEMENTS.feature_conn_id
  6  	     WHERE a.current_designation is null
  7  	     and a.current_low is null
  8  	     and a.current_high is null)
  9  /

1 row deleted.

SCOTT@orcl_11gR2> select * from b$gc_count_temp
  2  /

CONNECTION_ID_TEMP CURRENT_DESIGNATION CURRENT_LOW CURRENT_HIGH
------------------ ------------------- ----------- ------------
                 2                   3           4            5

1 row selected.

SCOTT@orcl_11gR2> select * from complements
  2  /

FEATURE_CONN_ID
---------------
              1
              2

2 rows selected.

SCOTT@orcl_11gR2>

Re: delete statement with inner join [message #499241 is a reply to message #499239] Mon, 14 March 2011 04:42 Go to previous message
Michel Cadot
Messages: 68774
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
And also it would help to give us your Oracle version (4 decimals) to get an appropriate answer and not one that your version can't execute.

Regards
Michel
Previous Topic: Update String anywhere in text
Next Topic: Problem with cursors in pl/sql procedure (merged)
Goto Forum:
  


Current Time: Fri Jan 16 10:55:18 CST 2026