Tag Archives: mysql

More nifty SQL: insert if not exists

Quite often you want to insert a record into a table, but only if it doesn’t already exist. OK, you could first do a SELECT query to check for existence, and then do the insert, but it’s clumsy and raises … Continue reading

Posted in Databases | Tagged , | Leave a comment

SQL query to find duplicate rows

This is one of those things I can never remember how to do when I need to do it. I don’t know why, it’s really quite simple: SELECT emailaddress, firstname, lastname, COUNT(emailaddress) FROM customers GROUP BY emailaddress HAVING COUNT(emailaddress) > … Continue reading

Posted in Databases | Tagged , | Leave a comment

Intermediate PHP and MySQL course

Since 1999 I’ve been teaching online for the Open University. It may not pay brilliantly, but it’s regular income and I really enjoy doing it; OU students often overcome major barriers to achieve a qualification they missed out on earlier … Continue reading

Posted in Databases, PHP, Web development | Tagged , | Leave a comment

Date handling in PHP and MySQL

It’s always a real headache manipulating dates between PHP and MySQL, because PHP’s date functions assume Unix timestamps, while MySQL has its own internal date format. They both have excellent built-in functions for handling dates, but they are fundamentally incompatible. … Continue reading

Posted in Databases, PHP, Web development | Tagged | Leave a comment