Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,399 Programmers. There are 1,479 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

General use of Select in MYSQL

 
Reply to this topicStart new topic

> General use of Select in MYSQL

no2pencil
Group Icon



post 19 Nov, 2007 - 08:03 AM
Post #1


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.


Register to Make This Ad Go Away!


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 5/17/08 06:20AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month