Re: MySQL Query Puzzle
| From: | Shafiq Rehman | Date: | Mon, 19 Jul 2010 05:23:16 +0000 |
| Subject: | Re: MySQL Query Puzzle | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306981@lists.php.net to get a copy of this message | ||
On Mon, Jul 19, 2010 at 10:44 AM, Peter <peters@egrabber.com> wrote:
> Hi All,
>
> I have a table which contain's some duplicate rows. I just want to delete
> the duplicate records alone
> not original records.
>
> Assume my table as look as below
>
> column1 column2
> 1
> a
> 1
> a
> 2
> b
> 3
> c
> 3
> c
>
>
>
> i want the above table need to be as below, After executing the mysql
> query.
>
> column1
> column2
> 1
> a
> 2
> b
> 3
> c
>
>
>
>
> Thanks in advance..
>
> Regards
> Peter
>
Create a table with similar structure and add UNIQUE INDEX on both
columns. Execute the following query:
INSERT IGNORE INTO NEW_TABLE (column1, column2) SELECT column1,
column2 FROM OLD_TABLE
This will give you distinct rows as required.
--
Keep Smiling :-)
Shafiq Rehman
Blog: http://shafiq.pk, Twitter: http://twitter.com/shafiq