Using Functions to Perform System-Related Operations : Function In Select : Function : SQL / MySQL examples (example source code) Organized by topic

SQL / MySQL
1. Backup Load
2. Command MySQL
3. Cursor
4. Data Type
5. Database
6. Date Time
7. Flow Control
8. Function
9. Insert Delete Update
10. Join
11. Key
12. Math
13. Procedure Function
14. Select Clause
15. String
16. Table Index
17. Transaction
18. Trigger
19. User Permission
20. View
21. Where Clause
Java
Java Tutorial
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
SQL / MySQL » Function » Function In Select 
Using Functions to Perform System-Related Operations

/*
mysql> Drop table DVDs;
Query OK, 0 rows affected (1.66 sec)

mysql> CREATE TABLE DVDs (
    ->    ID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    ->    Name VARCHAR(60) NOT NULL,
    ->    NumDisks TINYINT NOT NULL DEFAULT 1,
    ->    RatingID VARCHAR(4) NOT NULL,
    ->    StatID CHAR(3) NOT NULL
    -> )
    -> ENGINE=INNODB;
Query OK, 0 rows affected (1.02 sec)

mysql> INSERT INTO DVDs (Name, NumDisks, RatingID, StatID)
    -> VALUES ('Christmas', 1, 'NR', 's1'),
    ->        ('Doc',       1, 'G',  's2'),
    ->        ('Africa',    1, 'PG', 's1'),
    ->        ('Falcon',    1, 'NR', 's2'),
    ->        ('Amadeus',   1, 'PG', 's2'),
    ->        ('Show',      2, 'NR', 's2'),
    ->        ('View',      1, 'NR', 's1'),
    ->        ('Mash',      2, 'R',  's2');
Query OK, 8 rows affected (0.22 sec)
Records: 8  Duplicates: 0  Warnings: 0

mysql> SELECT SQL_CALC_FOUND_ROWS Name
    -> FROM DVDs
    -> WHERE StatID='s2'
    -> ORDER BY Name
    -> LIMIT 2;
+---------+
| Name    |
+---------+
| Amadeus |
| Doc     |
+---------+
2 rows in set (0.21 sec)

*/

Drop table DVDs;

CREATE TABLE DVDs (
   ID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
   Name VARCHAR(60NOT NULL,
   NumDisks TINYINT NOT NULL DEFAULT 1,
   RatingID VARCHAR(4NOT NULL,
   StatID CHAR(3NOT NULL
)
ENGINE=INNODB;

INSERT INTO DVDs (Name, NumDisks, RatingID, StatID)
VALUES ('Christmas', 1'NR', 's1'),
       ('Doc',       1'G',  's2'),
       ('Africa',    1'PG', 's1'),
       ('Falcon',    1'NR', 's2'),
       ('Amadeus',   1'PG', 's2'),
       ('Show',      2'NR', 's2'),
       ('View',      1'NR', 's1'),
       ('Mash',      2'R',  's2');
  


SELECT SQL_CALC_FOUND_ROWS Name
FROM DVDs
WHERE StatID='s2'
ORDER BY Name
LIMIT 2;

           
       
Related examples in the same category
Home | Contact Us
Copyright 2003 - 07 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.