user3697634
user3697634

Reputation:

deleteing matching values from table1 when found in table2

i am a newbie and i cannot write a subquery.i have two table one csv and other is master.i want to delete records from csv where values present in master.

my csv table

id(PK)    phone
1         1234
2         2345
3         7777

my master table

urn    phone
1      9988
2      1234
3      7777

to find the values present in csv and master i query.

select phone from csv where phone in (select phone from master)

  phone
  1234
  7777

now how can i delete the matching values from csv in a single query from php?

Upvotes: 0

Views: 27

Answers (2)

juergen d
juergen d

Reputation: 204924

delete csv
from csv
join master on csv.phone = master.phone

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1271231

Basically, you can replace the select with delete from:

delete from csv
    where phone in (select phone from master);

Upvotes: 1

Related Questions