LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Sql delete entries (https://www.linuxquestions.org/questions/linux-newbie-8/sql-delete-entries-4175475499/)

wackysiya 09-01-2013 07:29 PM

Sql delete entries
 
Hi All,

I was trying to delete all entries from a table whose corresponding id number entries are not found in a associated different table.

If I want to display all entries of a table1 (using id_number) which are not present in the other table I used this and it worked perfectly.
SELECT * from table1 WHERE id_number NOT IN (SELECT id_number FROM TABLE2)


However when I use the delete command it doesn't work
DELETE * from table1 WHERE id_number NOT IN (SELECT id_number FROM TABLE2)


Please could some one correct where am I doing wrong?

Thanks

Berhanie 09-01-2013 07:48 PM

syntax: delete from table_name where condition. see DELETE.
Code:

DELETE from table1 WHERE id_number NOT IN (SELECT id_number FROM TABLE2)

kooru 09-02-2013 03:19 AM

As said by Berhanie, your syntax is wrong.
The correct statement is "delete from table_name", not "delete * from table_name".

http://www.w3schools.com/sql/sql_delete.asp


All times are GMT -5. The time now is 03:54 PM.