Ad Code

Responsive Advertisement

SQL Syntax

                               SQL Syntax


PART 1 : 

SQL is followed by an interesting group of rules and guidelines called Syntax. This tutorial gives you a quick start with SQL by listing all the basic SQL sentencing structures. 


All SQL guidelines start standard one of the key witticisms like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and all directions end standard a semicolon (;). 


The point in addition to significant to note here is that SQL is unaware to the case, which means that SELECT and select have the same meaning in SQL directions. While MySQL makes the difference in table names. So if you work with MySQL, then you have to give table names as they exist in the database.


Some of the SQL commands in addition to important : 

  • SELECT : extracts data from a database 
  • UPDATE : Updates database data 
  • DELETE : deletes data from a database 
  • INSERT INTO : inserts new data into a database 
  • CREATE DATABASE : creates a new database 
  • ALTER DATABASE : changes a database 
  • CREATE TABLE : creates a new table 
  • ALTER TABLE : changes a table 
  • DROP TABLE : removes a table 
  • CREATE INDEX : creates a queue (search key) 
  • DROP INDEX : removes a queue


SQL SELECT Statement :



A database contains in addition to often one or more tables. Each scene is identified as standard a name (e.g. "Customers" or "Orders"). Tables contain records (lines) with data. 

In this tutorial, we will use the well-known Northwind sample database (included in MS Access and MS SQL Server).


Most of the activities you need to do in a database are done with SQL directions.

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

Example : 

SELECT * FROM Customers;

SELECT CustomerID , Country FROM Customers;


SQL DISTINCT Clause : 


This SQL tutorial explains remark use the condition SQL DISTINCT with syntax and examples.

The SQL DISTINCT provision is used to remove duplicates from the results set of a SELECT guidance.


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

Settings or restraints :  

Joints 

Columns or calculations you want to retrieve. 

Tables 

The tables from which you want to retrieve records. There must be at least one table listed in the PROvisoFROM. 

Where conditions 

Optional. The conditions that must be met for the files to be selected.


Note :

When a single joint is provided in the DISTINCT provision, the query returns the unique values of that joint. 

When multiple joints are provided in the DISTINCT statement, the query recovers unique combinations for the listed joints. 

In SQL, the DISTINCT provision does not ignore null values. So when you use the DISTINCT condition in your SQL guidance, your set of results will include NULL as a separate value.

Example : 


SELECT DISTINCT state
FROM suppliers;
SELECT DISTINCT city, state,.......
FROM suppliers;
SELECT DISTINCT *
FROM suppliers;


SQL WHERE Clause :

The SQL WHERE statement is used to specify a condition when extracting data from a single table or by joining multiple tables. If the given condition is met, it returns only a specific value from the table. You must use the WHERE proviso to filter the records and get only the necessary records. 

The WHERE condition is not only used in the SELECT statement, but it is also used in the update, the DELETE statement, and so forth, which we would examine in the following chapters.

Syntax 


The basic syntax of the SELECT statement with the WHERE statement is shown below.


SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION;

Example : 



SELECT  * FROM  ARTICLE WHERE PRICE > 200 ; 

SELECT  Name FROM  ARTICLE WHERE PRICE > 200 ; 






Post a Comment

1 Comments

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)