TechiWarehouse.Com


Top 3 Products & Services

1.
2.
3.


Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/santanaservices/public_html/techiwarehouse.com/cms/engine.php on line 37

Dated: Feb. 11, 2006

Related Categories

PHP Programming
SQL

By Donald W. Hyatt

We have already used the SELECT command in MySQL to list the contents of a table. For instance, if a user had already connected to the database "games" and wanted to review the scores, the following would list all the contents of that table:

mysql> SELECT * FROM scores;

The system will reply:

+---------+------+
| Name    | Num  |
+---------+------+
| Phyllis |  987 |
| Randy   | 1285 |
| Don     |  919 |
| Mark    |    0 |
| Mary    |  567 |
| Bob     |   23 |
| Pete    |  456 |
| Sally   |  333 |
+---------+------+
8 rows in set (0.00 sec)   How to Create a Simple Query Using SELECT

More Advanced Queries

  1. To List By Numerical Order

    mysql> SELECT * FROM scores ORDER BY Num;
    +---------+------+
    | Name    | Num  |
    +---------+------+
    | Mark    |    0 |
    | Bob     |   23 |
    | Sally   |  333 |
    | Pete    |  456 |
    | Mary    |  567 |
    | Don     |  919 |
    | Phyllis |  987 |
    | Randy   | 1285 |
    +---------+------+
    8 rows in set (0.00 sec)
    
  2. To List By Alphabetical Order

    mysql> SELECT * FROM scores ORDER BY Name;
    +---------+------+
    | Name    | Num  |
    +---------+------+
    | Bob     |   23 |
    | Don     |  919 |
    | Mark    |    0 |
    | Mary    |  567 |
    | Pete    |  456 |
    | Phyllis |  987 |
    | Randy   | 1285 |
    | Sally   |  333 |
    +---------+------+
    8 rows in set (0.01 sec)
    
    
  3. List Only the Names of the Losers

    mysql> SELECT Name FROM scores WHERE (Num < 100);
    +------+
    | Name |
    +------+
    | Mark |
    | Bob  |
    +------+
    2 rows in set (0.00 sec) 
    
  4. List the Winners by Order of High Score
    Note: This will be a long Query, and will be split on multiple lines:

    mysql> SELECT Num, Name FROM scores
          -> WHERE (Num > 900)
          -> ORDER BY Num DESC;
       
    +------+---------+
    | Num  | Name    |
    +------+---------+
    | 1285 | Randy   |
    |  987 | Phyllis |
    |  919 | Don     |
    +------+---------+
    3 rows in set (0.00 sec) 
    

Now that you've gotten free know-how on this topic, try to grow your skills even faster with online video training. Then finally, put these skills to the test and make a name for yourself by offering these skills to others by becoming a freelancer. There are literally 2000+ new projects that are posted every single freakin' day, no lie!


Previous Article

Next Article




Facebook