Databases

How to sort MySQL results based on date, id, name

Posted on 2011-02-05 03:42:27, by Daniel in ComputersDatabases

postimage

Here it is, another tutorial on how to sort results in mysql.This tutorial is done using phpMyAdmin instead of mysql console like last time. You can find that tutorial hereWe will use a wordpress database to see results for ourselves.Let's first sort results based on date and results should show from the newest date to the oldest (descending).Example:SELECT `ID`,`post_date` FROM `wp_posts` order by `post_date` descIn this example we only get ID and post_dateThe results are as follows:If you want the results to show from oldest to newest we can use asc (ascending)Example:SELECT `ID`,`post_date` FROM `wp_posts` order by `post_date` ascIf you want to order results by ID then you simply make some small changes.Example:SELECT `ID`,`post_date` FROM `wp_posts` order by `ID` ascYou can do the same thing if you want to sort ... Read More

Databases

How to sort(arrange) results from MySQL based on the first letter

Posted on 2011-01-31 04:51:50, by Daniel in ComputersDatabases

postimage

This article is a tutorial for people that want to select(display) results from a MySQL table based on the first letter of the contents of that letter.The concept is pretty easy. If you installed wamp as a local server (windows, apache, mysql, php) you can access your phpMyAdmin by going to http://localhost/phpmyadmin (You don't have to access mysql from the command line). You will need to have a basic understanding with phpMyAdmin and MySQLIn this example I will show results from the MySQL console.Ok so let's say that you want to select results that contain numeric values.Here is the sql results that you will get when you execute this command. As a test I will use a wordpress database.select `post_title` from `wp_posts` where left(`post_title`,1) REGEXP('[0-9]') and `post_status`='publish';Since I don't have ... Read More