Page 1 of 1

General use of Select in MYSQL

#1 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5303
  • View blog
  • Posts: 27,188
  • Joined: 10-May 07

Posted 19 November 2007 - 08:03 AM

General use of Select in MYSQL

This really is a how-to for beginners in MYSQL.
One of the important things to remember, is that case, for the most part, is ignored in MYSQL. So SELECT is the same as select.
It is also important to note that every command must be followed by the semi-colon, just as in the examples that follow.

Opening your database.

At the mysql prompt, the command show will help you get started.

Quote

mysql> show databases;

This will return all of the databases in mysql. To open one of the databases, try the following:

Quote

mysql> use DATABASE;


With the database open, you can look at all of the tables that currently exist.

Quote

mysql> show TABLES;


You won't have to 'use' or 'select' the table. The select command actually allows you to select the column within the given TABLE.

Quote

mysql> select first,last from TABLE;


This will select the column labeled first & the column labeled last from the given TABLE. You can use an * to select every column.

Quote

mysql> select * from TABLE;


If you don't care for the "side-to-side" look, you can get a column: value look using back-slash G.

Quote

mysql> select first,last from TABLE\G


You can also help make your output easier to read using limit.

Quote

mysql> select first,last from TABLE limit 5\G


Add order to your output using the order by option.

Quote

mysql> select first,last from TABLE limit 5 order by first\G


The data that we have retrieved so far was always displayed in the order in which it was stored in the table. Here I will show you how to filter the output results by asending or descending values. This will work with both alphabetical & numerical values.

Quote

mysql> select first,last from TABLE limit 5 order by first ASC\G
mysql> select first,last from TABLE limit 5 order by first DESC\G


This tutorial should get you well on your way to using the select statement in MYSQL.

Is This A Good Question/Topic? 1
  • +

Replies To: General use of Select in MYSQL

#2 sfw  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 24-April 08

Posted 10 March 2010 - 12:52 PM

very helpful. thank you. i'll do more
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1