0

I am having an issue exporting data from a MySQL database. Essentially, I have some records in the database that are duplicates (some users signed up twice and there was no server side code to stop them from doing so).

So, to get all of the distinct values, I use this:

SELECT *
FROM users
GROUP BY email
ORDER BY user_id;

This is pretty straight forward and gives me exactly the data I want so I can rebuild the database. The issue is that when the data is exported from phpMyAdmin in a sql file, there are no quotes around the values in the email field. So, reimporting this into a database throws an error.

How can I get the data without having to put quotes around 13,000 email address manually so I can reimport this data??

Sethen
  • 11,140
  • 6
  • 34
  • 65

1 Answers1

1

Create a copy of the table using a script based on the below code

SELECT CONCAT('''', email, '''') AS email, rest_of_your_columns
FROM users
GROUP BY email, rest_of_your_columns
ORDER BY user_id
INTO new_users_table

In this case, the new table is called "new_users_table". It's the same table as your original table except all emails have single quotes encompassing them now.

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248