Everyone Know MySQL is an open-source relational database management system (RDBMS). Its name is a combination of “My”, the name of co-founder Michael Widenius’s daughter, and “SQL”, the abbreviation for Structured Query Language. Every web developer should know MySQL. It uses widely by every developer in the world. Here we’ve prepared a short and to-the-point introduction to the basics of MySQL. Within the article, you will find our interactive editors for writing and executing your code. Do your best and never afraid to experiment, “More you run, More You Reach to your goal” Either in a field or in the editor.
- Query for Selecting Columns from a Table
This is perhaps the most widely used SQL query. In the example below, we are extracting the “Customer_ID” column or attribute from the table “Customer”.
SELECT Customer_ID FROM Customer;
If you want to display all the attributes from a particular table, this is the right query to use:
SELECT * FROM Customer;
- Query for Outputting Data Using a Constraint
This query retrieves the specified attributes from the table on the constraint;
Customer ID =0010.
SELECT Customer_ID, NAME FROM Customer WHERE Customer_ID = '0010';
- Query for Outputting Sorted Data Using “Group By”
The ‘Group By’ property groups the resulting data according to the specified attribute.
SELECT NAME, Age FROM Customer WHERE Age > 40 GROUP BY Age ORDER BY NAME;
- Query for Outputting Sorted Data Using ‘Order By’
This query orders the results with respect to the attribute which is referenced to using “Order By” , Example – if that attribute is an integer data type, then the result would either be sorted in ascending or descending order; likewise, if the data type is a String then the result would be ordered in alphabetical order.
SELECT Customer_ID, NAME FROM Customer WHERE CITY = 'NEW YORK' ORDER BY Customer_ID;
The ordering of the result can also be set manually, using “ASC” for ascending and “DESC” for descending.
SELECT Customer_ID, NAME FROM Customer WHERE CITY = 'New YORK' ORDER BY Customer_ID asc;
Queries for Data Manipulation Using Math Functions
There are a lot of built-in math functions like COUNT and AVG which provide basic functionalities of counting the number of results and averaging them respectively.
- Data Manipulation Using “COUNT”
This query displays the total number of customers by counting each Customer ID. In addition, it groups the results according to the country of each customer.
SELECT COUNT(Customer_ID), Country FROM Customer GROUP BY Country;
- Data Manipulation Using SUM
SUM calculates the total of the attribute that is given to it as an argument
SELECT SUM(Salary)FROM Customer WHERE Age < 30;
- Data Manipulation Using AVG
Getting the Average of present data we have.
SELECT AVG(Price)FROM Products;
- Making Column Labels/Alias More Friendly
Aliasing column labels give us the convenience of renaming a column label to something more readable. There is a tradeoff when naming columns to make them succinct results in reduced readability in subsequent daily use
SELECT Item AS item_description FROM Orders
You can also view : –
I hope this post helped you to know Learn MySQL Important Queries – Part 1. To get the latest news and updates follow us on twitter & facebook, subscribe to our YouTube channel. And If you have any query then please let us know by using the comment form.