Back-End Development SQL basics

SQL select statement


Some of the most used SQL statements

  • SELECT – extracts data from a database
  • UPDATE – updates data in a database
  • DELETE – deletes data from a database
  • INSERT INTO – inserts new data into a database
  • CREATE DATABASE – creates a new database
  • ALTER DATABASE – modifies a database
  • CREATE TABLE – creates a new table
  • ALTER TABLE – modifies a table
  • DROP TABLE – deletes a table
  • CREATE INDEX – creates an index (search key)
  • DROP INDEX – deletes an index

SQL select statement

The select statement in sql is used to select or extract data from a database.
The result is some rows from the table.
Syntax:

Example:

Consider a sample database-Customer table

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #001,sec-19 c chd

1.SELECT * from Customer;
RESULT:This query results all rows from table Customer.

C.id C.name C.contact C.address
123eed3 Ramesh 987654321 #12,sec-4 mohali
aa22103 Tarun 987650000 #12,sec-14 b chd
00146hh Sia 812300912 #212,sec-86 panchukula
144dcv4 Rahul 700912366 #001,sec-19 c chd

2.SELECT c.id,c.name from Customer;
RESULT:This query results two columns that are named, from the table.

Consider a sample database-Customer table

C.id C.name
123eed3 Ramesh
aa22103 Tarun
00146hh Sia
144dcv4 Rahul