In MySQL, there is a statement called SELECT which is not at all case sensitive according to MySQL query I'm just doing all caps because it looks cool when writing this article. Actually, It's just common practice to write the commands upper-case.
- So SELECT statement is generally a statement used to fetch data from a particular table let it be full data or let it be the selected data or specific data for example.
- Today we are gonna see how SELECT is used in MySQL and does operations with it.
- Also, we will see how we do some fun things with it.
SELECT * from table_name; -- * fetches all of the table content and displays it.
NOTE: Any statement in MySQL is not at all case sensitive
For demo purposes, we will use a table called customers which will look like this.
Now we know that using * fetches all the content of a table and throws it to us.
Let us do a simple fun thing using SELECT.
We will be doing the following things using select:
- Select first name and last name and also the points column from the table.
- We will add increment points of 20 and alias it with a new column name and display it.
SELECT first_name, last_name, points, points+20 as 'incremented points' from customers;
So as we discussed I have selected the first name, last name, points column from the Customers table and added 20 points to column 'points' used 'as' to name it as the incremented points or we can say I aliased it and displayed both old points and newly added points data for reference.