Delete Rows from a table except a MYSQL amount

Asked

Viewed 38 times

1

I have in a table the columns:

codigo, cliente, token_md, val, cartcodigo, clientenome, clientesobrenome, clientecpf, clientenascimento

I need to delete exactly 46,550 rows from this table, no order concerns.

  • 1

    Makes a delete ... where codigo in (select ... limit 46550), but it’s really weird that you need something like this...

1 answer

0

Delete LIMIT We can’t limit the number of rows, one way to do that, is to create a temporary table limiting the number of rows, and then we remove the original table and recreate it based on the temporary one. Thus:

1.Creation of the temporary table:

CREATE TABLE tabela_temporaria
  SELECT codigo
        ,cliente
        ,token_md
        ,val
        ,cartcodigo
        ,clientenome
        ,clientesobrenome
        ,clientecpf
        ,clientenascimento
    FROM tabela
   LIMIT > 46550

2.Then we remove the original table:

DROP TABLE tabela;

3.Recreate original table based on season

CREATE TABLE tabela
  SELECT codigo
        ,cliente
        ,token_md
        ,val
        ,cartcodigo
        ,clientenome
        ,clientesobrenome
        ,clientecpf
        ,clientenascimento
    FROM tabela_temporaria
  • 1

    But isn’t there just leaving the items he wants to remove? Wouldn’t LIMIT > 46550?

  • Oo.. thanks @adventistaam I will not justify myself. I erred and I assume :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.