How to use select Statement in MySQL?

Ads
 

How to use select Statement in MySQL?

Hi, How to use select Statement in MySQL? I want to learn the various ways to use the SQL select statement.

Thanks

View Answers

June 26, 2016 at 5:56 AM

Hi,

What is the use of MySQL select clause?

MySQL select clause is used to select the data from table based on various criteria. It allows to selectively get the data from database table.

Here are various ways to use the select statement in MySQL

Suppose we have following table:

CREATE TABLE email
(
first_name varchar(20),
last_name varchar(20),
email varchar(40),
email_count Int
)

Then we can get the data using various select statement.

Select all data:

select * from email;

Above query displays all the data from email table.

Select particular columns from table:

Here are various ways to use select statement:

select first_name from email;

select first_name,last_name from email;

select email from email;


select email, email_count from email;

select <column1, column2,...> from table;

Here is the sample examples with various select statement:

mysql> select * from email;
+------------+-----------+----------------------+-------------+
| first_name | last_name | email                | email_count |
+------------+-----------+----------------------+-------------+
| Deepak     | Kumar     | [email protected] |         100 |
| Rajeev     | Singh     | [email protected] |         500 |
| Dinesh     | Singh     | [email protected] |         200 |
| John       | T         | [email protected]   |         400 |
| Ishu       | roy       | NULL                 |         800 |
+------------+-----------+----------------------+-------------+
5 rows in set (0.00 sec)

mysql> select first_name from email;
+------------+
| first_name |
+------------+
| Deepak     |
| Rajeev     |
| Dinesh     |
| John       |
| Ishu       |
+------------+
5 rows in set (0.00 sec)

mysql> select first_name,last_name from email;
+------------+-----------+
| first_name | last_name |
+------------+-----------+
| Deepak     | Kumar     |
| Rajeev     | Singh     |
| Dinesh     | Singh     |
| John       | T         |
| Ishu       | roy       |
+------------+-----------+
5 rows in set (0.00 sec)

mysql> select first_name,last_name,email from email;
+------------+-----------+----------------------+
| first_name | last_name | email                |
+------------+-----------+----------------------+
| Deepak     | Kumar     | [email protected] |
| Rajeev     | Singh     | [email protected] |
| Dinesh     | Singh     | [email protected] |
| John       | T         | [email protected]   |
| Ishu       | roy       | NULL                 |
+------------+-----------+----------------------+
5 rows in set (0.00 sec)

mysql> select email from email;
+----------------------+
| email                |
+----------------------+
| [email protected] |
| [email protected] |
| [email protected] |
| [email protected]   |
| NULL                 |
+----------------------+
5 rows in set (0.00 sec)

mysql> select email, email_count from email;
+----------------------+-------------+
| email                | email_count |
+----------------------+-------------+
| [email protected] |         100 |
| [email protected] |         500 |
| [email protected] |         200 |
| [email protected]   |         400 |
| NULL                 |         800 |
+----------------------+-------------+
5 rows in set (0.00 sec)

mysql> desc email;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| first_name  | varchar(20) | YES  |     | NULL    |       |
| last_name   | varchar(20) | YES  |     | NULL    |       |
| email       | varchar(40) | YES  |     | NULL    |       |
| email_count | int(11)     | YES  |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)

mysql>

Thanks

Ads









Related Tutorials/Questions & Answers:
How to use select Statement in MySQL?
How to use 'if' statement in jsp page?
Advertisements
SQL Select, HQL Select Example, HQL Select Query
Help with SELECT/JOIN statement
Use if statement with LOOP statement
SQL SELECT DISTINCT Statement
use of return statement
How to display all the rows in JSP ,MySQL select condition statement IN dept_table
where clause in select statement
SQL SELECT DISTINCT Statement
Use Compound Statement in JSP Code
Select Statement in SQL, SQL Tutorial
Use Break Statement in jsp code
Use DECLARE Statement in Procedure
Use DEFAULT Statement in Procedure
ModuleNotFoundError: No module named 'mysqlx-connector'
Use DECLARE Statement in Procedure
how to use group by in nested query
Use DEFAULT Statement in Procedure
How to break statement in JSP
How to break statement in JSP
How to break statement in JSP
How to break statement in JSP
How to use switch statement in jsp code
how I do select from select in hql
Hibernate 5 MySQL5 Dialect
Hibernate 5 MySQL5 Dialect
Hibernate 5 MySQL5 Dialect
JDBC: Select Records using Prepared Statement
Use if in velocity
Use HANDLER Statement in Cursors

Ads