Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete with join on single table...

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have a query which matches records with similar 7 and 6 digit primary keys...
I wish to delete the matching 7 digit records only...
The query below returns: '#1242 - Subquery returns more than 1 row'

I know I could write a loop in PHP to accomplish this; but, would like to write a proper query in MySQL to accomplish same...

The join matches 6 digit keys to 7 digit ones with a leading '1'...

Query:
Code:
DELETE FROM `mbbgmc_eraq_ro_2016-05-03` WHERE `roid` = (
SELECT z.x FROM (
SELECT `six`.`roid`, `seven`.`roid` as x 
FROM `mbbgmc_eraq_ro_2016-05-03` as seven
INNER JOIN `mbbgmc_eraq_ro_2016-05-03` as six
ON `seven`.`roid` LIKE CONCAT('1',`six`.`roid`)
WHERE `seven`.`postdate` > '2016-03-20') as z )

Thanks in advance for suggestions on how to resolve...

-A
 
Figured it out...
Need IN instead of =

-A
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top