SQL
SQL vs MySQL: What's the Difference Between SQL and MySQL?
In this tutorial, we will discuss the key difference between SQL and MySQL. Before discussing SQL...
You can retrieve data from the table using a SELECT statement.
Syntax:
SELECT [column names] FROM [table_name]
Here,
Step 1) We have a table "tutorials" with 2 columns "id" and "tutorial_name". Lets query it. Use the following query to list data in the table
SELECT id,tutorial_name FROM tutorials;
NOTE: Use the command \c to connect to the database that contains the table you want to query. In our case, we are connected to database gtupapers.
Step 2) If you want to view all the columns in a particular table, we can use the asterisk (*) wildcard character. This means it checks every possibility and, as a result, It will return every column.
SELECT * FROM tutorials;
It displays all the records of the tutorials table.
Step 3) You can use the ORDER clause to sort data in a table based on a particular column. The ORDER clause organizes data in A to Z order.
SELECT * FROM tutorials ORDER BY id;
You can sort from Z to A using "DESC" after the "ORDER BY" statement.
SELECT * FROM tutorials ORDER BY id DESC;
Step 4) The DISTINCT clause can be used to remove duplicate rows from the result. It keeps one row for each group of duplicates.
Syntax: SELECT DISTINCT column_1 FROM table_name;
Lets query Distinct id values from our table tutorials
SELECT DISTINCT(id) FROM tutorials;
Step 5) You can use the LIMIT clause to restrict the number of records returned by the SELECT query
SELECT * FROM tutorials LIMIT 4;
Step 1) In the Object Tree
Step 2) In the Panel on the right,
SELECT [column names] FROM [table_name] [clause]
Here, are the various parameters
Various clauses are:
* | Fetches records for all the rows in the table |
DISTINCT | This option helps you to removes duplicates from the result. |
ORDER BY | Sort Rows based on a column Default Sort Order is Ascending. Use Keyword DESC to sort in Descending order |
LIMIT | It restricts the number of records returned by the query. |
In this tutorial, we will discuss the key difference between SQL and MySQL. Before discussing SQL...
Aggregate Functions are all about Performing calculations on multiple rows Of a single column of a...
What is Package in Oracle? PL/SQL package is a logical grouping of a related subprogram...
In this tutorial, you will learn- SQLite constraint Primary Key Not null constraint DEFAULT...
What is SELECT query in MySQL? SELECT QUERY is used to fetch the data from the MySQL database....
What is Identifiers? Identifiers are nothing but a name that is given to a PL/SQL object. The...