How to use select Statement in MySQL?

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?
Help with SELECT/JOIN statement
Advertisements
SQL SELECT DISTINCT Statement
where clause in select statement
SQL SELECT DISTINCT Statement
Select Statement in SQL, SQL Tutorial
How to display all the rows in JSP ,MySQL select condition statement IN dept_table
ModuleNotFoundError: No module named 'mysqlx-connector'
How to use 'if' statement in jsp page?
SQL Select, HQL Select Example, HQL Select Query
How to break statement in JSP
How to break statement in JSP
How to break statement in JSP
How to break statement in JSP
Hibernate 5 MySQL5 Dialect
Hibernate 5 MySQL5 Dialect
Hibernate 5 MySQL5 Dialect
how I do select from select in hql
Use if statement with LOOP statement
JDBC: Select Records using Prepared Statement
JDBC Batch Example With SQL Select Statement
JDBC Select Statement Example
Select Records Using Prepared Statement
Using Select Statements in JDBC
how to select second combobox value .
use of return statement
how to operate on select box using ajax in struts2?
how to operate on select box using ajax in struts2?
How to use switch statement in jsp code
in string how will write the return statement..........?
Use DECLARE Statement in Procedure

Ads