How to Display Data Table in MySql

How to display data table in mysql - The SELECT command is used to display something. Something here can be any amount of data from the table and can also be an expression. With SELECT we can adjust the display or output according to the desired view.
Previously first review articles about:
The basic form of the SELECT data command from the table is as follows:
SELECT [field | * ]FROM table_name [WHERE condition];
How to show table data in mysql
Consider some examples of SELECT commands from the following student table!
1. Displays all data or records (*) from the student table
SELECT * FROM student;
And if the above query is executed then the results will be displayed as follows:
How to Display Data Table in MySql

2. Displays the studentnumber field and the name of all the students in the student table.
SELECT studentnumber, name FROM student;
If the above query is executed then the results will be displayed as follows:
How to Display Data Table in MySql

3. Displays data of students who have studentnumber 201051162
SELECT * FROM student WHERE studentnumber = 201051162;
The above query result is as follows:
How to Display Data Table in MySql

4. Displays data of all students located outside Jakarta
SELECT * FROM student WHERE address != 'Jakarta';
The above query result is as follows:
How to Display Data Table in MySql

Here is a comparison operator that can be used to compare two values in MySQL:
= Operator, will be TRUE if the comparable value is equal.
The operator! = Or <>, will be TRUE if the comparable value is NOT SAME (different).
> Operator, will be TRUE if the first value is greater than the second value.
The operator> =, will be TRUE if the first value is greater than or equal to the second value.
The <operator, will be TRUE if the first value is less than the second value.
The <= operator, will be TRUE if the first value is less than or equal to the second value.
5. Displays data of all students who are addressed in Jakarta and born in 1992.
SELECT * FROM student WHERE address = 'Jakarta' && YEAR(dateofbirth) = '1992';
The above query result is as follows:
How to Display Data Table in MySql

Here are the connecting operators that can be used to connect between two conditions in MySQL:
Operator && or AND, will connect two conditions which will be TRUE if both conditions are TRUE.
Operator || Or OR, will connect two conditions which will be TRUE if one or both conditions are TRUE.
The operator!, Will reverse the value of a logical condition.
Information
The YEAR function in the above query will generate the YEAR value of a date. In addition to the YEAR function, there is also a MONTH function that will generate the MONTH name from the date, the DAY function that will generate the day of a date, and many other functions related to the date.
6. Displays studentnumber, name and age of all students.
SELECT studentnumber, name, YEAR(now())-YEAR(dateofbirth) AS age FROM student;
The above query result is as follows:
How to Display Data Table in MySql

Information
In the above query there is a YEAR function that will take a year from a date. Now the function now () will return the date and time of the system when the query is executed. Age calculation process is aligned with the name 'age'. To replace use the US command followed by the alternate name.
7. Displays all students with code 53 at the beginning of code 5
SELECT * FROM student WHERE SUBSTRING(studentnumber,5,2)='53';
The above query result is as follows:
How to Display Data Table in MySql

Information
In the query above there is a function SUBSTRING useful to cut a string. The SUBSTRING function format is as follows:
SUBSTRING (field, start, long)
8. Display all student data in sequence by name with ORDER BY command
SELECT * FROM student ORDER BY name;
The above query result is as follows:
How to Display Data Table in MySql

9. Display all student data in sequence based on nim by DESCENDING
SELECT * FROM student ORDER BY studentnumber DESC;
The above query result is as follows:
How to Display Data Table in MySql

10. Displaying the first 4 records (data) from the student table in sequence based on studentnumber with LIMIT
SELECT * FROM student ORDER BY studentnumber LIMIT 0,4;
The above query result is as follows:
How to Display Data Table in MySql

Information
In the above query the LIMIT form is used to limit the display results. LIMIT is widely used to display relatively large data. The LIMIT function format is as follows:
LIMIT start, count_record
That article from us on How to display data table in mysql, hopefully the above article can help you in learning php programming language.

Comments