Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

SELECT Statement



The SQL SELECT Statement


The SQL SELECT statement is used to retrieve data from one or more tables in a database. It is one of the most fundamental and commonly used SQL commands.

Here's the basic syntax of the SELECT statement:


SELECT column1, column2, ...
FROM table_name;


In this syntax:

Example:

Let's say we have a table named employees with columns employee_id, first_name, last_name, and salary, and we want to retrieve data from all columns:


SELECT *
FROM employees;


This query will return all rows and columns from the employees table.

You can also specify specific columns to retrieve:


SELECT employee_id, first_name, last_name
FROM employees;


This query will return only the employee_id, first_name, and last_name columns from the employees table.

Additionally, you can use the DISTINCT keyword to retrieve unique rows:


SELECT DISTINCT column1, column2, ...
FROM table_name;


For example, to retrieve unique department values from the employees table:


SELECT DISTINCT department
FROM employees;


The SELECT statement is versatile and allows you to filter, sort, and aggregate data using various clauses such as WHERE, ORDER BY, GROUP BY, HAVING, and more. It's fundamental for querying and retrieving data from a database in SQL.



Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java