Posts Tagged ‘MySQL’

MySQL: GROUP BY on DATETIME field

This item was filled under [ MySQL ]

Often webmasters want to sort out data on the basis of Dates when timestamp is stored as datetime in MySQL. To obtain the desired result, simply query:
SELECT DATE_FORMAT(MyDate, '%d %M %Y') AS Date, COUNT(*) AS numRows FROM Table1 GROUP BY Date;

Continue reading...

The basics of MySQL Views

This item was filled under [ MySQL ]

Before diving into any technicalities, I would like to share a little about “Views”. What is a VIEW, what is the benefit of it?
A view is a virtual or logical table composed of the result set of a query. Unlike ordinary tables (base tables) in a relational database, a view is not part of the [...]

Continue reading...

Setting next AUTOINCREMENT value

This item was filled under [ MySQL ]

By default, MySQL starts auto-incrementing from value 1. To start with value other than 1, you can set that value with CREATE TABLE or ALTER TABLE, like this:
mysql> ALTER TABLE [tablename] AUTO_INCREMENT = [number];
An alternate way of doing this is, simply insert a row in your Table and enter the next auto-increment value.
Enjoy! =)

Continue reading...