MySQL Select Statement

By using Select stament, you can read the data of single or multiple cells form one or more tables.

SYNTAX SELECT:
SELECT column1, column2,...,columnN FROM table ;
SELECT * FROM table;
* refers to all columns.

Example: Creating the table below and reading the table values by using MySQL.

PRODUCT TABLE (products)

ID Product Name Price £ Description
1 3D Glasses 14.49 High quality 3D glasses for 3D projectors.
2 Projector 400 HD and 3D ready Home teather projector.
3 Projector Screen 60 Perfect home teather experience with 90'' screen.

1. Create the products table

mysql> CREATE TABLE products ( ID TINYINT(2) NOT NULL AUTO_INCREMENT,
->product_name VARCHAR(30),
->price DECIMAL (6,2),
->description TEXT,
->PRIMARY KEY (ID));

2. Show Columns

show columns

3. Insert Data

Insert Single Row

mysql> INSERT INTO products(product_name, price, description) 
->VALUES ('3D Glasses', 14.49, 'High quality 3D glasses for 3D projectors.');

Insert Rest of the data

mysql> INSERT INTO products(product_name, price, description) 
->VALUES ('Projector', 400, 'HD and 3D ready Home teather projector.') ,
-> ('Projector Screen', 60, 'Perfect home teather experience with 90 in screen.');

4. Display all the rows inserted

mysql> SELECT * from products;

5. SELECT with Where Clause

Logical Where Operators

=
!=
>
<
>=
<=
BETWEEN
LIKE
IN

Select statement with where clause and AND / OR operators

mysql> SELECT * FROM products WHERE price=400 OR price=14.49;