Scrolling through the entire product table four records at a time : Limits « Select Clause « SQL / MySQL






Scrolling through the entire product table four records at a time

      
mysql>
mysql> CREATE TABLE product(
    ->     cust_num MEDIUMINT NOT NULL AUTO_INCREMENT,
    ->     cust_title TINYINT,
    ->     cust_last CHAR(20) NOT NULL,
    ->     cust_first CHAR(15) NOT NULL,
    ->     cust_suffix ENUM('Jr.', 'II', 'III','IV', 'V', 'M.D.','PhD'),
    ->     cust_add1 CHAR(30) NOT NULL,
    ->     cust_add2 CHAR(10),
    ->     cust_city CHAR(18) NOT NULL,
    ->     cust_state CHAR(2) NOT NULL,
    ->     cust_zip1 CHAR(5)NOT NULL,
    ->     cust_zip2 CHAR(4),
    ->     cust_duckname CHAR(25) NOT NULL,
    ->     cust_duckbday DATE,
    ->     PRIMARY KEY (cust_num)
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 1, 'XML', 'Red', 'III', '1022 N.E. Sea of Rye', 'A207', 'Seacouver', 'WA', '98601', '3464', 'Netrek Rules'
, '1967:10:21');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 4, 'SQL', 'Vicki', 0, '2004 Singleton Dr.', 0, 'Freedom', 'KS', '67209', '4321', 'Frida Kahlo de Tomayo',
'1948:03:21');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 9, 'HTML', 'Chantel', 0, '1567 Terra Cotta Way', 0,  'Chicago', 'IL', '89129', '4444', 'Bianca', '1971:07:
29');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 7, 'Robert', 'David', 'Sr.', '20113 Open Road Highway', '#6', 'Blacktop', 'AZ', '00606', '1952', 'Harley',
 '1949:08:00');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 5, 'Kazui', 'Wonko', 'PhD', '42 Cube Farm Lane', 'Gatehouse', 'Vlimpt', 'CA', '45362', 0, 'Fitzwhistle', '
1961:12:04');
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 6, 'iPhone', 'Karen', 0, '3113 Picket Fence Lane', 0,  'Fedora', 'VT', '41927', '5698', 'Tess D''urbervill
e', '1948:08:19');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql> INSERT INTO product VALUES
    -> (NULL, 8, 'Mac', 'Jenny', 0, '9 Wishing Well Court', 0, 'Meadowlark Hill', 'KS', '67048', '1234', 'Spike', '1961:
03:21');
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql>
mysql>
mysql>
mysql> SELECT cust_num, cust_first, cust_last FROM product LIMIT 0, 4;
+----------+------------+-----------+
| cust_num | cust_first | cust_last |
+----------+------------+-----------+
|        1 | Red        | XML       |
|        2 | Vicki      | SQL       |
|        3 | Chantel    | HTML      |
|        4 | David      | Robert    |
+----------+------------+-----------+
4 rows in set (0.00 sec)

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

   
    
    
    
    
    
  








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.Determining the Number of Records Suppressed by LIMIT (SQL_CALC_FOUND_ROWS, FOUND_ROWS)
10.Limiting a Selection Using LIMIT
11.Use ORDER BY to sort the result set. Then you can use LIMIT to find smallest and largest values.
12.Order the rows with the largest SUM( ) values first and use LIMIT to select the first record
13.A DELETE statement can be qualified by using an ORDER BY and a LIMIT clause
14.The LIMIT clause takes two arguments, as the following syntax shows: LIMIT [,]
15.SELECT statement includes a LIMIT clause that specifies an offset value of 3 and a row count value of 4
16.WHERE clause can include additional logical operators and expressions that further limit the results returned
17.Limit to first three columns
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