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.
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:
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:
Of course, you can also run the above two statements together, like this:
The examples on this page use the Sakila sample database.