Limit to first three columns : Limits « Select Clause « SQL / MySQL






Limit to first three columns

      
mysql>
mysql>
mysql> CREATE   TABLE MATCHES
    ->         (MATCHNO        INTEGER      NOT NULL,
    ->          TEAMNO         INTEGER      NOT NULL,
    ->          EmployeeNO       INTEGER      NOT NULL,
    ->          WON            SMALLINT     NOT NULL,
    ->          LOST           SMALLINT     NOT NULL,
    ->          PRIMARY KEY    (MATCHNO)            );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO MATCHES VALUES ( 1, 1,   6, 3, 1);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 2, 1,   6, 2, 3);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 3, 1,   6, 3, 0);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 4, 1,  44, 3, 2);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 5, 1,  83, 0, 3);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 6, 1,   2, 1, 3);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 7, 1,  57, 3, 0);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 8, 1,   8, 0, 3);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES ( 9, 2,  27, 3, 2);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES (10, 2, 104, 3, 2);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES (11, 2, 112, 2, 3);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES (12, 2, 112, 1, 3);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO MATCHES VALUES (13, 2,   8, 0, 3);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> SELECT   EmployeeNO, COUNT(*) AS NUMBER
    -> FROM     MATCHES
    -> WHERE    WON > LOST
    -> GROUP BY EmployeeNO
    -> ORDER BY NUMBER DESC
    -> LIMIT    3;
+------------+--------+
| EmployeeNO | NUMBER |
+------------+--------+
|          6 |      2 |
|         44 |      1 |
|         57 |      1 |
+------------+--------+
3 rows in set (0.00 sec)

mysql>
mysql> drop table matches;
Query OK, 0 rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
  








Related examples in the same category

1.Limit the query results: Get 3 Most Expensive Products
2.Use LIMIT in SELECT
3.Use LIMIT
4.Another ORDER BY and limit
5.Simple LIMIT
6.Retrieving the Top Five Students
7.ORDER and limit
8.Limits and order
9.Scrolling through the entire product table four records at a time
10.Determining the Number of Records Suppressed by LIMIT (SQL_CALC_FOUND_ROWS, FOUND_ROWS)
11.Limiting a Selection Using LIMIT
12.Use ORDER BY to sort the result set. Then you can use LIMIT to find smallest and largest values.
13.Order the rows with the largest SUM( ) values first and use LIMIT to select the first record
14.A DELETE statement can be qualified by using an ORDER BY and a LIMIT clause
15.The LIMIT clause takes two arguments, as the following syntax shows: LIMIT [,]
16.SELECT statement includes a LIMIT clause that specifies an offset value of 3 and a row count value of 4
17.WHERE clause can include additional logical operators and expressions that further limit the results returned
18.LIMIT 5 OFFSET 3
19.Delete with order by and limit clause
20.Pulling a Section from the Middle of a Result Set
21.Tell MySQL what offset to use, from which result to start limiting.
22.The default offset is 0, so by specifying an offset of 1, you're taking the second record.
23.Selecting Records from the Beginning or End of a Result Set
24.Processing the First or Last n Records
25.Limiting the Number of Results
26.But LIMIT allows you to return only that record