0

I am using mysql and php. I am unable to delete any records even if records exist to meet the condition specified in the query , please help to identify the problem, my query is

Table1 (id, LName) table2(id,LName)

delete from table1 where Lname in (select Lname from table2); 
Ajeet
  • 49
  • 1
  • 6

3 Answers3

2

delete from table1 where Lname in (select Lname from table2);

Its Work for me. Maybe it have case problem so try like this

delete from table1 where upper(Lname) in (select upper(Lname) from table2);

Sathish
  • 4,419
  • 4
  • 30
  • 59
0

According to the table structure you provided in your comment, the query should be somewhat like this:

delete from table1
where name in 
(select name 
 from table2)

But according to your question, it seems your table don't seem to have a column named 'Lname'.

If your column name is actually 'Lname', then the query can be re-written as:

delete from table1
where Lname in 
(select Lname 
 from table2)

Please, please be extra careful mentioning table structure, you MUST post the appropriate name of your tables and columns, and with correct spelling.

0

Another option is using a JOIN:-

DELETE table1
FROM table1 
INNER JOIN table2
ON table1.Lname table2.Lname

but your original SQL should work

Kickstart
  • 21,403
  • 2
  • 21
  • 33