Related Content
Solving Query Performance Problems With The MySQL Slow Query Log
MySQL's slow query log is a key component in your MySQL administration setup. Whilst normal logging can help you in terms of tracking down issues with your database system, the slow query log can help you track down issues in your database setup before they become problematic.
Creating An Authentication System With PHP and MariaDB
Using frameworks to handle the authentication of your PHP application is perfectly fine to do, and normally encouraged. They abstract away all of the complexity of managing users and sessions that need to work in order to allow your application to function.
Case Insensitive Like Searches In MySQL
I needed to create a query that did a case insensitive search using the LIKE command in MySQL and I quickly realised that in order to do this I would need to alter both the parameter and the table data to be the same case. This can be done by using the MySQL UPPER() command on the table data and the strtoupper() PHP function on the input data.
Connecting To A Non Standard MySQL Socket In PHP
Connecting to a MySQL database in PHP is usually not a difficult thing to do, in fact it is one of the first things that many tutorials will go though. However, there are certain curcumstances that require more information than the standard host, password and username details.
Count Number Of Characters In A String With MySQL
Today I needed to grab some data from a table where there was more than one occurrence of a string within another string. Basically, I needed to find all URL's from a table that were more than 3 levels deep (i.e. with 3 slashes), but realised there wasn't a function to do this in MySQL.
MySQL Order Table By Character Length
As part of debugging a bit of code I needed to know the longest possible field lengths that a record contains. You might need to know this if you are performing a database migration. The following query returns a field, along with the length of the string, and orders the results by the number of characters in that string.
Comments
Submitted by Jamie Bicknell on Fri, 09/19/2008 - 09:44
PermalinkSubmitted by giHlZp8M8D on Fri, 09/19/2008 - 10:38
PermalinkSubmitted by Nalle on Sun, 02/01/2009 - 23:01
PermalinkVery nice. I tweaked your example a little to find records that are missing by date
CREATE TABLE IF NOT EXISTS `sequence` (
`id` BIGINT NOT NULL AUTO_INCREMENT ,
`date` DATETIME NOT NULL ,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB;
# missing 10/2, 10/12, and 10/13
INSERT INTO sequence (date) values ('2011-10-01 00:00:00');
INSERT INTO sequence (date) values ('2011-10-03 00:00:00');
INSERT INTO sequence (date) values ('2011-10-04 00:00:00');
INSERT INTO sequence (date) values ('2011-10-05 00:00:00');
INSERT INTO sequence (date) values ('2011-10-06 00:00:00');
INSERT INTO sequence (date) values ('2011-10-07 00:00:00');
INSERT INTO sequence (date) values ('2011-10-08 00:00:00');
INSERT INTO sequence (date) values ('2011-10-09 00:00:00');
INSERT INTO sequence (date) values ('2011-10-10 00:00:00');
INSERT INTO sequence (date) values ('2011-10-11 00:00:00');
INSERT INTO sequence (date) values ('2011-10-14 00:00:00');
INSERT INTO sequence (date) values ('2011-10-15 00:00:00');
INSERT INTO sequence (date) values ('2011-10-16 00:00:00');
INSERT INTO sequence (date) values ('2011-10-17 00:00:00');
INSERT INTO sequence (date) values ('2011-10-18 00:00:00');
INSERT INTO sequence (date) values ('2011-10-19 00:00:00');
INSERT INTO sequence (date) values ('2011-10-20 00:00:00');
mysql> SELECT
-> DATE_ADD(t1.date, INTERVAL 1 DAY) AS 'Missing From',
-> DATE_ADD( MIN(t2.date), INTERVAL -1 DAY) AS 'To'
-> FROM sequence AS t1, sequence AS t2
-> WHERE t1.date GROUP BY t1.date
-> HAVING t1.date < DATE_ADD( MIN(t2.date), INTERVAL -1 DAY);
+---------------------+---------------------+
| Missing From | To |
+---------------------+---------------------+
| 2011-10-02 00:00:00 | 2011-10-02 00:00:00 |
| 2011-10-12 00:00:00 | 2011-10-13 00:00:00 |
+---------------------+---------------------+
2 rows in set (0.00 sec)
Submitted by andy on Wed, 10/19/2011 - 21:07
PermalinkThat's awesome! I'm sure I'll have a use for that one day.
Thanks for your input Andy :)
Submitted by giHlZp8M8D on Wed, 10/19/2011 - 21:08
PermalinkAdd new comment