your image

MySQL SELECT Statement

quackit
Related Topic
:- MYSQL

MySQL SELECT Statement

 

The SELECT statement is probably the most commonly used SQL statement. The SELECT statement simply selects data from the database as specified by you.

 

SELECT * FROM sakila.actor;

The above statement selects all records from the actor table in the sakila database.

By using sakila.actor we are specifying the database and table (i.e. db.table). You can also run this query without specifying the database. If you do that, MySQL will use the default database (whichever database has been specified as the default database).

You can make the sakila database the default database by running this code:

 

 
USE sakila;

Now, whenever you run any queries, the query will be run against the sakila database (unless you specify another database in your query).

Now you can modify the top SELECT statement to the following:

 

 
SELECT * FROM actor;

Of course, you can also run the above two statements together, like this:

 

 
USE sakila;
SELECT * FROM actor;

The examples on this page use the Sakila sample database.

Comments