Posts Tagged ‘SQL’

SQL query generator for changing WordPress tables

Friday, April 16th, 2010

I recently went through the ordeal of changing the prefixes of the WordPress tables from the default wp_ to something more random, I have created the following to help anyone wanting to go through the same process.

Related posts:

  1. Database query in SQL to select first unique record

Database query in SQL to select first unique record

Monday, June 2nd, 2008

Here’s a quick code snippet to create a query that selects all unique records from field1, and selects the first corresponding record in field2

SELECT DISTINCT field1, First(field2) AS field2first
FROM table1
GROUP BY field1;

The function First, can be substituted for Last, Min, Max, depending on desired returned record. In the example above, table1 is the recordset, field1 is the field which you want unique records only, and field2 are the corresponding records, field2first is just an alias.