<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4902137339535858867</atom:id><lastBuildDate>Fri, 01 Nov 2024 07:43:09 +0000</lastBuildDate><category>AND</category><category>BETWEEN</category><category>DCL</category><category>DDL</category><category>DML</category><category>IN</category><category>IS NULL</category><category>SQL Alias</category><category>SQL CREATE</category><category>SQL CREATE TABLE Statement</category><category>SQL Commands</category><category>SQL Delete</category><category>SQL Delete Statement</category><category>SQL GROUP BY</category><category>SQL GROUP BY Clause</category><category>SQL GROUP Functions</category><category>SQL HAVING</category><category>SQL HAVING Clause</category><category>SQL INSERT</category><category>SQL INSERT  Statement</category><category>SQL LIKE</category><category>SQL Logical Operators</category><category>SQL ORDER BY</category><category>SQL Operators</category><category>SQL SELECT</category><category>SQL SELECT Statement</category><category>SQL UPDATE</category><category>SQL UPDATE Statement</category><category>SQL WHERE</category><category>TCL</category><category>WHERE Clause</category><title>Learning SQL - SQL Query, SQL Statements, Learn SQL Basics</title><description>SQL Tutorial, SQL Statement, SQL Query, Learn by examples! This beginner SQL Tutorial website teaches you the basics of SQL and how to write SQL queries.</description><link>http://learninsql.blogspot.com/</link><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><generator>Blogger</generator><openSearch:totalResults>15</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-2753374186926120451</guid><pubDate>Sat, 07 Jan 2012 17:35:00 +0000</pubDate><atom:updated>2012-01-07T09:35:52.475-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL CREATE</category><category domain="http://www.blogger.com/atom/ns#">SQL CREATE TABLE Statement</category><title>SQL CREATE</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The CREATE TABLE Statement is used to create tables to store  data. Integrity Constraints like primary key, unique key, foreign key  can be defined for the columns while creating the table. The integrity  constraints can be defined at column level or table level. The  implementation and the syntax of the CREATE Statements differs for  different RDBMS.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;The Syntax for the CREATE TABLE Statement is:&lt;/h3&gt;&lt;code&gt; CREATE TABLE table_name  &lt;br /&gt;
(column_name1 datatype,  &lt;br /&gt;
column_name2 datatype,  &lt;br /&gt;
... column_nameN datatype &lt;br /&gt;
); &lt;/code&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;em&gt;&lt;strong&gt;table_name&lt;/strong&gt;&lt;/em&gt;  - is the name of the table.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;column_name1, column_name2....&lt;/strong&gt;&lt;/em&gt; - is the name of the columns&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;datatype&lt;/strong&gt;&lt;/em&gt;    - is the datatype for the column like char, date, number etc.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; If you want to create the employee table, the statement would be like,&lt;br /&gt;
&lt;code&gt; CREATE TABLE employee &lt;br /&gt;
( id number(5), &lt;br /&gt;
name char(20), &lt;br /&gt;
dept  char(10), &lt;br /&gt;
age number(2), &lt;br /&gt;
salary number(10), &lt;br /&gt;
location char(10) &lt;br /&gt;
); &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
In Oracle database, the datatype for an integer column is represented as &quot;number&quot;. In Sybase it is represented as &quot;int&quot;. Oracle provides another way of creating a table.&lt;br /&gt;
&lt;code&gt; CREATE TABLE temp_employee &lt;br /&gt;
SELECT * FROM employee  &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
In the above statement, temp_employee table is created with the same number of columns and datatype as employee table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-create.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-5887274775007277712</guid><pubDate>Sat, 07 Jan 2012 17:32:00 +0000</pubDate><atom:updated>2012-01-07T09:42:24.561-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Delete</category><category domain="http://www.blogger.com/atom/ns#">SQL Delete Statement</category><title>SQL Delete</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The DELETE Statement is used to delete rows from a table.&lt;br /&gt;
&lt;br /&gt;
The Syntax of a SQL DELETE statement is: &lt;br /&gt;
&lt;code&gt; DELETE FROM table_name [WHERE condition];  &lt;/code&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;table_name -- the table name which has to be updated.&lt;/li&gt;
&lt;/ul&gt;&lt;span class=&quot;black&quot;&gt; &lt;b&gt;NOTE: &lt;/b&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;note&quot;&gt;The  WHERE clause in the sql delete command  is optional and it identifies  the rows in the column that gets deleted. If you do not include the  WHERE clause all the rows in the table is deleted, so be careful while  writing a DELETE query without WHERE clause. &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; To delete an employee with id 100 from the employee table, the sql delete query would be like,&lt;br /&gt;
&lt;code&gt; DELETE FROM employee WHERE id = 100; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
To delete all the rows from the employee table, the query would be like, &lt;br /&gt;
&lt;code&gt; DELETE FROM employee;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;&lt;span class=&quot;subtopic&quot;&gt;SQL TRUNCATE Statement&lt;/span&gt;&lt;/h1&gt;The SQL TRUNCATE command is used to delete all the rows from the table and free the space containing the table.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Syntax to TRUNCATE a table:&lt;/h3&gt;&lt;code&gt; TRUNCATE TABLE table_name; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; To delete all the rows from employee table, the query would be like, &lt;br /&gt;
&lt;code&gt; TRUNCATE TABLE employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Difference between DELETE and TRUNCATE Statements:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;  DELETE Statement:&lt;/b&gt; This command deletes only the rows from the  table based on the condition given in the where clause or deletes all  the rows from the table if no condition is specified. But it does not  free the space containing the table. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;TRUNCATE statement:&lt;/b&gt; This command is used to delete all the rows from the table and free the space containing the table.&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;&lt;span class=&quot;subtopic&quot;&gt;SQL DROP Statement:&lt;/span&gt;&lt;/h1&gt;The SQL DROP command is used to remove an object from the database.  If you drop a table, all the rows in the table is deleted and the table  structure is removed from the database. Once a table is dropped we  cannot get it back, so be careful while using RENAME command. When a  table is dropped all the references to the table will not be valid.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Syntax to drop a sql table structure:&lt;/b&gt;&lt;br /&gt;
&lt;code&gt; DROP TABLE table_name; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; To drop the table employee, the query would be like&lt;br /&gt;
&lt;code&gt; DROP TABLE employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Difference between DROP and TRUNCATE Statement:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
If a table is dropped, all the relationships with other tables will no  longer be valid, the integrity constraints will be dropped, grant or  access privileges on the table will also be dropped, if want use the  table again it has to be recreated with the integrity constraints,  access privileges and the  relationships with other tables should be  established again.  But, if a table is truncated, the table structure  remains the same, therefore any of the above problems will not exist.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-delete.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-687029633186800496</guid><pubDate>Sat, 07 Jan 2012 17:24:00 +0000</pubDate><atom:updated>2012-01-07T09:24:28.752-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL UPDATE</category><category domain="http://www.blogger.com/atom/ns#">SQL UPDATE Statement</category><title>SQL UPDATE</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The UPDATE Statement is used to modify the existing rows in a table.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;The Syntax for SQL UPDATE Command is: &lt;/h3&gt;&lt;code&gt; UPDATE table_name  &lt;br /&gt;
SET column_name1 = value1,  &lt;br /&gt;
column_name2 = value2, ...  &lt;br /&gt;
[WHERE condition]  &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;table_name - the table name which has to be updated.&lt;/li&gt;
&lt;li&gt;column_name1, column_name2.. - the columns that gets changed.&lt;/li&gt;
&lt;li&gt;value1, value2... - are the new values.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt; &lt;strong&gt;NOTE: &lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt;&lt;i&gt;In  the Update statement, WHERE clause identifies the rows that get  affected. If you do not include the WHERE clause, column values for all  the rows get affected.&lt;/i&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; To update the location of an employee, the sql update query would be like,&lt;br /&gt;
&lt;code&gt; UPDATE employee &lt;br /&gt;
SET location =&#39;Mysore&#39; &lt;br /&gt;
WHERE id = 101; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
To change the salaries of all the employees, the query would be,&lt;br /&gt;
&lt;code&gt;  UPDATE employee &lt;br /&gt;
SET salary = salary + (salary * 0.2);&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-update.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-4461436759009026978</guid><pubDate>Sat, 07 Jan 2012 17:20:00 +0000</pubDate><atom:updated>2012-01-07T09:21:47.319-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL INSERT</category><category domain="http://www.blogger.com/atom/ns#">SQL INSERT  Statement</category><title>SQL INSERT</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The INSERT Statement is used to add new rows of data to a table. We can insert data to a table in two ways,&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt; 1) Inserting the data directly to a table. &lt;/b&gt;&lt;br /&gt;
&lt;h3&gt;Syntax for SQL INSERT is: &lt;/h3&gt;&lt;code&gt; INSERT INTO TABLE_NAME &lt;br /&gt;
[ (col1, col2, col3,...colN)]  &lt;br /&gt;
VALUES (value1, value2, value3,...valueN);  &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;col1, col2,...colN -- the names of the columns in the table into which you want to insert data.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
While inserting a row, if you are adding value for all the columns of  the table you need not specify the column(s) name in the sql query.   But you need to make sure the order of the values is in the same order  as the columns in the table. The sql insert query will be as follows &lt;br /&gt;
&lt;code&gt; INSERT INTO TABLE_NAME &lt;br /&gt;
VALUES (value1, value2, value3,...valueN); &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; If you want to insert a row to  the employee table, the query would be like,&lt;br /&gt;
&lt;code&gt; INSERT INTO employee (id, name, dept, age, salary location) VALUES (105, &#39;Srinath&#39;, &#39;Aeronautics&#39;, 27, 33000); &lt;/code&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt; &lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE: &lt;/b&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;note&quot;&gt;When adding a row, only the characters or date values should be enclosed with single quotes. &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;  &lt;/i&gt;&lt;i&gt; If you are inserting data to all the columns, the column names can be  omitted.&lt;/i&gt; The above insert statement can also be written as,  &lt;br /&gt;
&lt;code&gt; INSERT INTO employee  &lt;br /&gt;
VALUES (105, &#39;Srinath&#39;, &#39;Aeronautics&#39;, 27, 33000);  &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;2) Inserting  data to a table through a select statement. &lt;/b&gt;&lt;br /&gt;
&lt;h3&gt;Syntax for SQL INSERT is:&lt;/h3&gt;&lt;code&gt; INSERT INTO table_name &lt;br /&gt;
[(column1, column2, ... columnN)] &lt;br /&gt;
SELECT column1, column2, ...columnN &lt;br /&gt;
FROM table_name [WHERE condition]; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; To insert a row into the employee table from a temporary table, the sql insert query would be like,&lt;br /&gt;
&lt;code&gt; INSERT INTO employee (id, name, dept, age, salary location) SELECT emp_id, emp_name, dept, age, salary, location  &lt;br /&gt;
FROM temp_employee;  &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
If you are inserting data to all the columns, the above insert statement can also be written as, &lt;br /&gt;
&lt;code&gt; INSERT INTO employee  &lt;br /&gt;
SELECT * FROM temp_employee; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt; &lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt; &lt;i&gt;We  have assumed the temp_employee table has columns emp_id, emp_name,  dept, age, salary, location in the above given order and the same  datatype.&lt;/i&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;IMPORTANT NOTE: &lt;/b&gt;&lt;br /&gt;
1) When adding a new row, you should ensure the datatype of the value and the column matches &lt;br /&gt;
2) You follow the integrity constraints, if any, defined for the table.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                                                                           &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-insert.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-8674138230034256754</guid><pubDate>Sat, 07 Jan 2012 17:15:00 +0000</pubDate><atom:updated>2012-01-07T09:15:50.632-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL HAVING</category><category domain="http://www.blogger.com/atom/ns#">SQL HAVING Clause</category><title>SQL HAVING</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Having clause is used to filter data based on the group functions.  This is similar to WHERE condition but is used with group functions.  Group functions cannot be used in WHERE Clause but can be used in HAVING  clause.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; If you want to select the department  that has total salary paid for its employees more than 25000, the sql  query would be like; &lt;br /&gt;
&lt;code&gt; SELECT dept, SUM (salary) &lt;br /&gt;
FROM employee &lt;br /&gt;
GROUP BY dept &lt;br /&gt;
HAVING SUM (salary) &amp;gt; 25000 &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be like:&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 359px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;99&quot;&gt;&lt;b&gt;dept&lt;/b&gt;&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;250&quot;&gt;&lt;b&gt;salary&lt;/b&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Electronics&lt;/td&gt;     &lt;td&gt;55000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Aeronautics&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;InfoTech&lt;/td&gt;     &lt;td&gt;30000&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
When WHERE, GROUP BY and HAVING clauses are used together in a SELECT  statement, the WHERE clause is processed first, then the rows that are  returned after the  WHERE clause is executed are grouped based on the  GROUP BY clause. Finally, any conditions on the group functions in the  HAVING clause are applied to the grouped rows before the final output is  displayed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-having.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-5313232445810306437</guid><pubDate>Sat, 07 Jan 2012 13:08:00 +0000</pubDate><atom:updated>2012-01-07T05:09:49.800-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL GROUP BY</category><category domain="http://www.blogger.com/atom/ns#">SQL GROUP BY Clause</category><title>SQL GROUP BY</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The SQL GROUP BY Clause is used along with the group functions to retrieve data grouped according to one or more columns.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; If you want to know the total amount of salary spent on each department, the query would be:&lt;br /&gt;
&lt;code&gt; SELECT dept, SUM (salary) &lt;br /&gt;
FROM employee &lt;br /&gt;
GROUP BY dept; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be like:&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 165px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;84&quot;&gt;dept &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;71&quot;&gt;salary &lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;  &lt;td&gt;----------------&lt;/td&gt;  &lt;td&gt;--------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;  &lt;td&gt;Electrical&lt;/td&gt;  &lt;td&gt;25000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;  &lt;td&gt;Electronics&lt;/td&gt;  &lt;td&gt;55000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Aeronautics&lt;/td&gt;  &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;InfoTech&lt;/td&gt;  &lt;td&gt;30000&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;black&quot;&gt; &lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt; &lt;i&gt;The group by clause should contain all the columns in the select list expect those used along with the group functions.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;code&gt; SELECT location, dept, SUM (salary) &lt;br /&gt;
FROM employee &lt;br /&gt;
GROUP BY location, dept;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be like:&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 215px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;66&quot;&gt;location &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;77&quot;&gt;dept &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;58&quot;&gt;salary &lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;  &lt;td&gt;---------------&lt;/td&gt;  &lt;td&gt;-----------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Bangalore&lt;/td&gt;  &lt;td&gt;Electrical&lt;/td&gt;  &lt;td&gt;25000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;  &lt;td&gt;Bangalore&lt;/td&gt;   &lt;td&gt;Electronics&lt;/td&gt;  &lt;td&gt;55000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Mysore&lt;/td&gt;     &lt;td&gt;Aeronautics&lt;/td&gt;  &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Mangalore&lt;/td&gt;     &lt;td&gt;InfoTech&lt;/td&gt;  &lt;td&gt;30000&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-group-by.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-130888519832280714</guid><pubDate>Sat, 07 Jan 2012 13:05:00 +0000</pubDate><atom:updated>2012-01-07T05:05:33.201-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL GROUP Functions</category><title>SQL GROUP Functions</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Group functions are built-in SQL functions that operate on  groups of rows and return one value for the entire group. These  functions are: &lt;strong&gt;COUNT, MAX, MIN, AVG, SUM, DISTINCT&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;  &lt;br /&gt;
&lt;strong&gt;SQL COUNT ():&lt;/strong&gt; This function returns the number of  rows in the table that satisfies the condition specified in the WHERE  condition. If the WHERE condition is not specified, then the query  returns the total number of rows in the table.&lt;br /&gt;
&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; If you want the number of employees in a particular department, the query would be:&lt;br /&gt;
&lt;code&gt; SELECT COUNT (*) FROM employee &lt;br /&gt;
WHERE dept = &#39;Electronics&#39;; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be &#39;2&#39; rows.&lt;br /&gt;
&lt;br /&gt;
If you want the total number of employees in all the department, the query would take the form:&lt;br /&gt;
&lt;code&gt; SELECT COUNT (*) FROM employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be &#39;5&#39; rows.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SQL DISTINCT():&lt;/strong&gt; This function is used to select the distinct rows.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; If you want to select all distinct department names from employee table, the query would be:&lt;br /&gt;
&lt;code&gt; SELECT DISTINCT dept FROM employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
To get the count of employees with unique name, the query would be:&lt;br /&gt;
&lt;code&gt; SELECT COUNT (DISTINCT name) FROM employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SQL MAX():&lt;/strong&gt; This function is used to get the maximum value from a column.&lt;br /&gt;
To get the maximum salary drawn by an employee, the query would be:&lt;br /&gt;
&lt;code&gt; SELECT MAX (salary) FROM employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SQL MIN():&lt;/strong&gt; This function is used to get the minimum value from a column.&lt;br /&gt;
To get the minimum salary drawn by an employee, he query would be:&lt;br /&gt;
&lt;code&gt; SELECT MIN (salary) FROM employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SQL AVG():&lt;/strong&gt; This function is used to get the average value of a numeric column. &lt;br /&gt;
To get the average salary, the query would be&lt;br /&gt;
&lt;code&gt; SELECT AVG (salary) FROM employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;SQL SUM():&lt;/strong&gt; This function is used to get the sum of a numeric column&lt;br /&gt;
To get the total salary given out to the employees,&lt;br /&gt;
&lt;code&gt; SELECT SUM (salary) FROM employee;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-group-functions.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-2162606372520367914</guid><pubDate>Sat, 07 Jan 2012 13:02:00 +0000</pubDate><atom:updated>2012-01-07T05:02:22.630-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL ORDER BY</category><title>SQL ORDER BY</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The ORDER BY clause is used in a SELECT statement to sort results  either in ascending or descending order. Oracle sorts query results in  ascending order by default.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Syntax for using SQL ORDER BY clause to sort data is:&lt;/h3&gt;&lt;code&gt; SELECT column-list &lt;br /&gt;
FROM table_name [WHERE condition] &lt;br /&gt;
[ORDER BY column1 [, column2, .. columnN] [DESC]];&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;strong&gt;database table &quot;employee&quot;;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 352px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot; bgcolor=&quot;#4284B0&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;29&quot;&gt; id &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;47&quot;&gt; name &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;66&quot;&gt; dept &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;35&quot;&gt; age &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;44&quot;&gt; salary &lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;105&quot;&gt; location &lt;/th&gt;       &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td&gt;100&lt;/td&gt;     &lt;td&gt;Ramesh&lt;/td&gt;  &lt;td&gt;Electrical&lt;/td&gt;  &lt;td&gt;24&lt;/td&gt;  &lt;td&gt;25000&lt;/td&gt;  &lt;td&gt;Bangalore&lt;/td&gt;    &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td&gt;101&lt;/td&gt;     &lt;td&gt;Hrithik &lt;/td&gt;  &lt;td&gt;Electronics&lt;/td&gt;  &lt;td&gt;28&lt;/td&gt;  &lt;td&gt;35000&lt;/td&gt;  &lt;td&gt;Bangalore&lt;/td&gt;    &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td&gt;102&lt;/td&gt;     &lt;td&gt;Harsha&lt;/td&gt;  &lt;td&gt;Aeronautics&lt;/td&gt;  &lt;td&gt;28&lt;/td&gt;  &lt;td&gt;35000&lt;/td&gt;  &lt;td&gt;Mysore&lt;/td&gt;    &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td&gt;103&lt;/td&gt;     &lt;td&gt;Soumya&lt;/td&gt;  &lt;td&gt;Electronics&lt;/td&gt;  &lt;td&gt;22&lt;/td&gt;  &lt;td&gt;20000&lt;/td&gt;  &lt;td&gt;Bangalore&lt;/td&gt;    &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td&gt;104&lt;/td&gt;     &lt;td&gt;Priya&lt;/td&gt;  &lt;td&gt;InfoTech&lt;/td&gt;  &lt;td&gt;25&lt;/td&gt;  &lt;td&gt;30000&lt;/td&gt;  &lt;td&gt;Mangalore&lt;/td&gt;    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; If you want to sort the employee table by salary of the employee, the sql query would be.&lt;br /&gt;
&lt;code&gt; SELECT name, salary FROM employee ORDER BY salary; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be like&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;salary&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;----------&lt;/td&gt;     &lt;td&gt;----------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Soumya&lt;/td&gt;     &lt;td&gt;20000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Ramesh&lt;/td&gt;     &lt;td&gt;25000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Priya&lt;/td&gt;     &lt;td&gt;30000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Hrithik&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Harsha&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
The query first sorts the result according to name and then displays it. You can also use more than one column in the ORDER BY clause. If you want to sort the employee table by the name and salary, the query would be like,&lt;br /&gt;
&lt;code&gt; SELECT name, salary FROM employee ORDER BY name, salary; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be like: &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 148px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;65&quot;&gt;name&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;73&quot;&gt;salary&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Soumya&lt;/td&gt;     &lt;td&gt;20000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Ramesh&lt;/td&gt;     &lt;td&gt;25000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Priya&lt;/td&gt;     &lt;td&gt;30000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Harsha&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Hrithik&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;black&quot;&gt; &lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;strong&gt;NOTE: &lt;/strong&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;note&quot;&gt;The columns specified in ORDER BY clause should be one of the columns selected in the SELECT column list. &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;  &lt;/i&gt;&lt;br /&gt;
You can represent the columns in the ORDER BY clause by specifying the  position of a column in the SELECT list, instead of writing the column  name. The above query can also be written as given below,&lt;br /&gt;
&lt;code&gt; SELECT name, salary FROM employee ORDER BY 1, 2; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
By default, the ORDER BY Clause sorts data in ascending order. If you  want to sort the data in descending order, you must explicitly specify  it as shown below.&lt;br /&gt;
&lt;code&gt; SELECT name, salary &lt;br /&gt;
FROM employee &lt;br /&gt;
ORDER BY name, salary DESC; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The above query sorts only the column &#39;salary&#39; in descending order and the column &#39;name&#39; by ascending order.&lt;br /&gt;
If you want to select both name and salary in descending order, the query would be as given below.&lt;br /&gt;
&lt;code&gt; SELECT name, salary &lt;br /&gt;
FROM employee &lt;br /&gt;
ORDER BY name DESC, salary DESC; &lt;/code&gt;&lt;br /&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;&lt;h3&gt;How to use expressions in the ORDER BY Clause?&lt;/h3&gt;Expressions in the ORDER BY clause of a SELECT statement. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;For example:&lt;/strong&gt;  If you want to display employee name,  current salary, and a 20% increase in the salary for only those  employees for whom the percentage increase in salary is greater than  30000 and in descending order of the increased price, the SELECT  statement can be written as shown below&lt;br /&gt;
&lt;code&gt; SELECT name, salary, salary*1.2 AS new_salary  &lt;br /&gt;
FROM employee  &lt;br /&gt;
WHERE salary*1.2 &amp;gt; 30000 &lt;br /&gt;
ORDER BY new_salary DESC; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output for the above query is as follows.&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;salary&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;new_salary&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;----------&lt;/td&gt;     &lt;td&gt;----------&lt;/td&gt;  &lt;td&gt;-------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Hrithik&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;  &lt;td&gt;37000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Harsha&lt;/td&gt;     &lt;td&gt;35000&lt;/td&gt;  &lt;td&gt;37000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Priya&lt;/td&gt;     &lt;td&gt;30000&lt;/td&gt;  &lt;td&gt;36000&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;black&quot;&gt; &lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt; &lt;i&gt;Aliases defined in the SELECT Statement can be used in ORDER BY Clause.&lt;/i&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-order-by.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-2341160657814740192</guid><pubDate>Sat, 07 Jan 2012 12:54:00 +0000</pubDate><atom:updated>2012-01-07T04:58:25.729-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AND</category><category domain="http://www.blogger.com/atom/ns#">BETWEEN</category><category domain="http://www.blogger.com/atom/ns#">IN</category><category domain="http://www.blogger.com/atom/ns#">IS NULL</category><category domain="http://www.blogger.com/atom/ns#">SQL LIKE</category><title>SQL LIKE, IN, BETWEEN.....</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;h1&gt;SQL Comparison Keywords&lt;/h1&gt;There are other comparison keywords available in sql which are used  to enhance the search capabilities of a sql query. They are &quot;IN&quot;,  &quot;BETWEEN...AND&quot;, &quot;IS NULL&quot;, &quot;LIKE&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 550px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot; bgcolor=&quot;#4284B0&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;150&quot;&gt;&lt;b&gt;Comparision Operators&lt;/b&gt;&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;400&quot;&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;left&quot;&gt;LIKE&lt;/td&gt;     &lt;td&gt;column value is similar to specified character(s).&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;left&quot;&gt;IN&lt;/td&gt;     &lt;td&gt;column value is equal to any one of a specified set of values.&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;left&quot;&gt;BETWEEN...AND&lt;/td&gt;     &lt;td&gt;column value is between two values, including the end values specified in the range.&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;left&quot;&gt;IS NULL&lt;/td&gt;     &lt;td&gt;column value does not exist.&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;&lt;h2&gt;SQL LIKE Operator&lt;/h2&gt;The LIKE operator is used to list all rows in a table whose column  values match a specified pattern. It is useful when you want to search  rows to match a specific pattern, or when you do not know the entire  value. For this purpose we use a wildcard character &#39;%&#39;. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For example:&lt;/b&gt; To select all the students whose name begins with &#39;S&#39; &lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE first_name LIKE &#39;S%&#39;;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be similar to: &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Stephen&lt;/td&gt;     &lt;td&gt;Fleming&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Shekar&lt;/td&gt;     &lt;td&gt;Gowda&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
The above select statement searches for all the rows where the first  letter of the column first_name is &#39;S&#39; and rest of the letters in the  name can be any character.&lt;br /&gt;
&lt;br /&gt;
There is another wildcard character you can use with LIKE operator. It  is the underscore character, &#39; _ &#39; . In a search string, the underscore  signifies a single character. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For example:&lt;/b&gt; to display all the names with &#39;a&#39; second character, &lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE first_name LIKE &#39;_a%&#39;; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be similar to: &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;black&quot;&gt; &lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt;Each  underscore act as a placeholder for only one character. So you can use  more than one underscore. Eg: &#39; __i% &#39;-this has two underscores towards  the left, &#39;S__j%&#39; - this has two underscores between character &#39;S&#39; and  &#39;i&#39;.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;SQL BETWEEN ... AND Operator&lt;/h2&gt;The operator BETWEEN and AND, are used to compare data for a range of values. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; to find the names of the students between age 10 to 15 years, the query would be like,&lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name, age &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE age BETWEEN 10 AND 15;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be similar to:&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;age&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;      &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;     &lt;td&gt;10&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Anajali&lt;/td&gt;     &lt;td&gt;Bhagwat&lt;/td&gt;     &lt;td&gt;12&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Shekar&lt;/td&gt;     &lt;td&gt;Gowda&lt;/td&gt;     &lt;td&gt;15&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;&lt;h2&gt;SQL IN Operator:&lt;/h2&gt;The IN operator is used when you want to compare a column with more than one value. It is similar to an OR condition.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For example:&lt;/b&gt; If you want to find the names of students who are studying either Maths or Science, the query would be like, &lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name, subject &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE subject IN (&#39;Maths&#39;, &#39;Science&#39;); &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be similar to: &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;subject&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;----------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Anajali&lt;/td&gt;     &lt;td&gt;Bhagwat&lt;/td&gt;     &lt;td&gt;Maths&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Shekar&lt;/td&gt;     &lt;td&gt;Gowda&lt;/td&gt;     &lt;td&gt;Maths&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;      &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;     &lt;td&gt;Science&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Stephen&lt;/td&gt;     &lt;td&gt;Fleming&lt;/td&gt;     &lt;td&gt;Science&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
You can include more subjects in the list like (&#39;maths&#39;,&#39;science&#39;,&#39;history&#39;)&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt; &lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt;&lt;i&gt; The data used to compare is case sensitive.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;note&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt; &lt;/span&gt;&lt;br /&gt;
&lt;h2&gt;SQL IS NULL Operator&lt;/h2&gt;A column value is NULL if it does not exist. The IS NULL operator is  used to display all the rows for columns that do not have a value.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; If you want to find the names of students who do not participate in any games, the query would be as given below&lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE games IS NULL &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
There would be no output as we have every student participate in a game  in the table student_details, else the names of the students who do not  participate in any games would be displayed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter  &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-like-in-between.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-8427498692620132006</guid><pubDate>Sat, 07 Jan 2012 12:48:00 +0000</pubDate><atom:updated>2012-01-07T04:48:30.354-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Logical Operators</category><title>SQL Logical Operators</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;There are three Logical Operators namely, AND, OR, and NOT. These  operators compare two conditions at a time to determine whether a row  can be selected for the output. When retrieving data using a SELECT  statement, you can use logical operators in the WHERE clause, which  allows you to combine more than one condition.&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 343px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot; bgcolor=&quot;#4284B0&quot;&gt;&lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Logical Operators&lt;/strong&gt;&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;252&quot;&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;OR&lt;/td&gt;     &lt;td&gt;For the row to be selected at least one of the conditions must be true.&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;AND&lt;/td&gt;     &lt;td&gt;For a row to be selected all the specified conditions must be true.&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;NOT&lt;/td&gt;     &lt;td&gt;For a row to be selected the specified condition must be false.&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;&lt;h2&gt;&quot;OR&quot; Logical Operator:&lt;/h2&gt;If you want to select rows that satisfy at least one of the given conditions, you can use the logical operator, OR.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;For example:&lt;/strong&gt; if you want to find the names of students who are studying either Maths or Science, the query would be like,&lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name, subject &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE subject = &#39;Maths&#39; OR subject = &#39;Science&#39; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be something like, &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;subject&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;----------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Anajali&lt;/td&gt;     &lt;td&gt;Bhagwat&lt;/td&gt;     &lt;td&gt;Maths&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Shekar&lt;/td&gt;     &lt;td&gt;Gowda&lt;/td&gt;     &lt;td&gt;Maths&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;      &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;     &lt;td&gt;Science&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Stephen&lt;/td&gt;     &lt;td&gt;Fleming&lt;/td&gt;     &lt;td&gt;Science&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
The following table describes how logical &quot;OR&quot; operator selects a row.&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 343px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot; bgcolor=&quot;#4284B0&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Column1 Satisfied?&lt;/strong&gt;&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Column2 Satisfied?&lt;/strong&gt;&lt;/th&gt;  &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Row Selected&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;  &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;NO&lt;/td&gt;  &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;NO&lt;/td&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;  &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;YES&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;NO&lt;/td&gt;     &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;NO&lt;/td&gt;  &lt;td align=&quot;center&quot; style=&quot;background-color: #cfe2f3;&quot;&gt;NO&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;&quot;AND&quot; Logical Operator:&lt;/h2&gt;If you want to select rows that must satisfy all the given conditions, you can use the logical operator, AND.  &lt;br /&gt;
&lt;strong&gt;For Example:&lt;/strong&gt; To find the names of the students between the age 10 to 15 years, the query would be like: &lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name, age &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE age &amp;gt;= 10 AND age &amp;lt;= 15;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be something like,  &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;age&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;      &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;     &lt;td&gt;10&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Anajali&lt;/td&gt;     &lt;td&gt;Bhagwat&lt;/td&gt;     &lt;td&gt;12&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Shekar&lt;/td&gt;     &lt;td&gt;Gowda&lt;/td&gt;     &lt;td&gt;15&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
The following table describes how logical &quot;AND&quot; operator selects a row.&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 343px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot; bgcolor=&quot;#4284B0&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Column1 Satisfied?&lt;/strong&gt;&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Column2 Satisfied?&lt;/strong&gt;&lt;/th&gt;  &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Row Selected&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;&lt;h2&gt;&quot;NOT&quot; Logical Operator:&lt;/h2&gt;If you want to find rows that do not satisfy a condition, you can use the logical operator, NOT. NOT results in the reverse of a condition. That is, if a condition is satisfied, then the row is not returned.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;For example:&lt;/strong&gt; If you want to find out the names of the students who do not play football, the query would be like: &lt;br /&gt;
&lt;code&gt; SELECT first_name, last_name, games &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE NOT games = &#39;Football&#39; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be something like, &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;games&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;----------------&lt;/td&gt;     &lt;td&gt;----------------&lt;/td&gt;     &lt;td&gt;-----------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;      &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;     &lt;td&gt;Cricket&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Stephen&lt;/td&gt;     &lt;td&gt;Fleming&lt;/td&gt;     &lt;td&gt;Cricket&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Shekar&lt;/td&gt;     &lt;td&gt;Gowda&lt;/td&gt;     &lt;td&gt;Badminton&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Priya&lt;/td&gt;     &lt;td&gt;Chandra&lt;/td&gt;     &lt;td&gt;Chess&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
The following table describes how logical &quot;NOT&quot; operator selects a row.&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 343px;&quot;&gt;&lt;tbody&gt;
&lt;tr align=&quot;center&quot; bgcolor=&quot;#4284B0&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Column1 Satisfied?&lt;/strong&gt;&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;NOT Column1 Satisfied?&lt;/strong&gt;&lt;/th&gt;  &lt;th scope=&quot;col&quot; width=&quot;81&quot;&gt;&lt;strong&gt;Row Selected&lt;/strong&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;NO&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;YES&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Nested Logical Operators:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
You can use multiple logical operators in an SQL statement. When you  combine the logical operators in a SELECT statement, the order in which  the statement is processed is&lt;br /&gt;
1) NOT &lt;br /&gt;
2) AND &lt;br /&gt;
3) OR&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;For example:&lt;/strong&gt; If you want to select the names of the students who age is between 10 and 15 years, or those who do not play football, the  &lt;br /&gt;
&lt;code&gt; SELECT statement would be&lt;br /&gt;
SELECT first_name, last_name, age, games &lt;br /&gt;
FROM student_details &lt;br /&gt;
WHERE age &amp;gt;= 10 AND age &amp;lt;= 15 &lt;br /&gt;
OR NOT games = &#39;Football&#39;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
The output would be something like, &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot;&gt;first_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;last_name&lt;/th&gt;     &lt;th scope=&quot;col&quot;&gt;age&lt;/th&gt;  &lt;th scope=&quot;col&quot;&gt;games&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;-------------&lt;/td&gt;     &lt;td&gt;--------&lt;/td&gt;  &lt;td&gt;------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;      &lt;td&gt;Rahul&lt;/td&gt;     &lt;td&gt;Sharma&lt;/td&gt;     &lt;td&gt;10&lt;/td&gt;  &lt;td&gt;Cricket&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Priya&lt;/td&gt;     &lt;td&gt;Chandra&lt;/td&gt;     &lt;td&gt;15&lt;/td&gt;  &lt;td&gt;Chess&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
In this case, the filter works as follows:&lt;br /&gt;
Condition 1: All the students you do not play football are selected.&lt;br /&gt;
Condition 2: All the students whose are aged between 10 and 15 are selected.&lt;br /&gt;
Condition 3: Finally the result is, the rows which satisfy atleast one of the above conditions is returned.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt; &lt;strong&gt;&amp;nbsp;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;/span&gt;&lt;i&gt;&lt;span class=&quot;note&quot;&gt; The order in which you phrase the condition is important, if the order changes you are likely to get a different result. &lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-logical-operators.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-5641123502269596495</guid><pubDate>Sat, 07 Jan 2012 12:43:00 +0000</pubDate><atom:updated>2012-01-07T04:44:19.320-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Operators</category><title>SQL Operators</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;There are two type of Operators, namely Comparison Operators  and  Logical Operators. These operators are used mainly in the WHERE clause,  HAVING clause to filter the data to be selected.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;Comparison Operators:&lt;/h2&gt;Comparison operators are used to compare the column data with specific values in a condition. &lt;br /&gt;
Comparison Operators are also used along with the SELECT statement to filter data based on specific conditions.&lt;br /&gt;
&lt;br /&gt;
The below table describes each comparison operator.&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 264px;&quot;&gt;&lt;tbody&gt;
&lt;tr bgcolor=&quot;#4284B0&quot;&gt;&lt;th scope=&quot;col&quot; width=&quot;116&quot;&gt;Comparison Operators&lt;/th&gt;   &lt;th scope=&quot;col&quot; width=&quot;138&quot;&gt;Description&lt;/th&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;= &lt;/td&gt;     &lt;td&gt;equal to&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;&amp;lt;&amp;gt;, != &lt;/td&gt;     &lt;td&gt;is not equal to&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;&amp;lt; &lt;/td&gt;     &lt;td&gt;less than&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;&amp;gt; &lt;/td&gt;     &lt;td&gt;greater than&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;&amp;gt;= &lt;/td&gt;     &lt;td&gt;greater than or equal to&lt;/td&gt;   &lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;     &lt;td align=&quot;center&quot;&gt;&amp;lt;= &lt;/td&gt;     &lt;td&gt;less than or equal to&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;h2&gt;&amp;nbsp;&lt;/h2&gt;&lt;h2&gt;Logical Operators:&lt;/h2&gt;There are three Logical Operators namely AND, OR and NOT.&lt;br /&gt;
Logical operators are discussed in detail in the next section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous  Chapter&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                                                                                         &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-operators.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-3202318764291649078</guid><pubDate>Sat, 07 Jan 2012 12:31:00 +0000</pubDate><atom:updated>2012-01-07T04:39:44.270-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL WHERE</category><category domain="http://www.blogger.com/atom/ns#">WHERE Clause</category><title>SQL WHERE</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;h1&gt;SQL WHERE Clause&lt;/h1&gt;The WHERE Clause is used when you want to retrieve specific  information from a table excluding other irrelevant data. For example,  when you want to see the  information about students in class 10th only  then you do need the information about the students in other class.  Retrieving information about all the students would increase the  processing time for the query.&lt;br /&gt;
&lt;br /&gt;
So SQL offers a feature called  WHERE clause, which we can use to  restrict the data that is retrieved. The condition you provide in the  WHERE clause filters the rows retrieved from the table and gives you  only those rows which you expected to see. WHERE clause can be used  along with SELECT, DELETE, UPDATE statements.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Syntax of SQL WHERE Clause: &lt;/h3&gt;&lt;code&gt;  WHERE {column or expression} comparison-operator value&lt;br /&gt;
&lt;br /&gt;
Syntax for a WHERE clause with Select statement is:&lt;br /&gt;
&lt;br /&gt;
SELECT &lt;i&gt;column_list&lt;/i&gt; FROM &lt;i&gt;table-name&lt;/i&gt; &lt;br /&gt;
WHERE &lt;i&gt;condition&lt;/i&gt;;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt; &lt;i&gt;column or expression&lt;/i&gt; - Is the column of a table or a expression&lt;/li&gt;
&lt;li&gt; &lt;i&gt;comparison-operator&lt;/i&gt; - operators like =  &amp;lt;  &amp;gt; etc.&lt;/li&gt;
&lt;li&gt; &lt;i&gt;value&lt;/i&gt; -  Any user value or a column name for comparison &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;b&gt;For Example:&lt;/b&gt; To find the name of a student with id 100, the query would be like:&lt;br /&gt;
&lt;code&gt;  SELECT first_name, last_name FROM student_details &lt;br /&gt;
WHERE id = 100;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
Comparison Operators and Logical Operators are used in WHERE Clause. These operators are discussed in the next chapter.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt;  Aliases defined for the columns in the SELECT statement cannot be used  in the WHERE clause to set conditions. Only aliases created for tables  can be used to reference the columns in the table.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;note&quot;&gt;&amp;nbsp;&lt;/span&gt; &lt;br /&gt;
&lt;h2&gt;How to use expressions in the WHERE Clause? &lt;/h2&gt;Expressions can also be used in the WHERE clause of the SELECT statement.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For example:&lt;/b&gt; Lets consider the employee table. If  you want to display employee name, current salary, and a 20% increase in  the salary for only those products where the percentage increase in  salary is greater than 30000, the SELECT statement can be written as  shown below: &lt;br /&gt;
&lt;code&gt;  SELECT name, salary, salary*1.2 AS new_salary FROM employee &lt;br /&gt;
WHERE salary*1.2 &amp;gt; 30000;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;b&gt;Output:&lt;/b&gt; &lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot; style=&quot;width: 200px;&quot;&gt;&lt;tbody&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;th scope=&quot;col&quot; width=&quot;55&quot;&gt;name&lt;/th&gt;  &lt;th scope=&quot;col&quot; width=&quot;54&quot;&gt;salary&lt;/th&gt;     &lt;th scope=&quot;col&quot; width=&quot;77&quot;&gt;new_salary&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;blue&quot;&gt;     &lt;td&gt;-----------&lt;/td&gt;     &lt;td&gt;----------&lt;/td&gt;  &lt;td&gt;----------------&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Hrithik&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;35000&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;37000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Harsha&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;35000&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;37000&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;green&quot;&gt;     &lt;td&gt;Priya&lt;/td&gt;     &lt;td align=&quot;center&quot;&gt;30000&lt;/td&gt;  &lt;td align=&quot;center&quot;&gt;360000&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt; Aliases defined in the SELECT Statement can be used in WHERE Clause.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&lt;a href=&quot;http://learninsql.blogspot.com/search/label/SQL%20Alias&quot; style=&quot;color: blue;&quot;&gt;&amp;lt;&amp;lt; Previous Chapter&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style=&quot;color: cyan;&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-where.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-6764074869569569993</guid><pubDate>Sat, 07 Jan 2012 06:02:00 +0000</pubDate><atom:updated>2012-01-09T01:45:23.114-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL Alias</category><title>SQL Alias</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;SQL Aliases are defined for columns and tables. Basically aliases is created to make the column selected more readable.    &lt;b&gt;For Example:&lt;/b&gt; To select the first name of all the students, the query would be like:&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Aliases for columns: &lt;/h3&gt;&lt;code&gt;  SELECT first_name AS Name FROM student_details;&lt;br /&gt;
or&lt;br /&gt;
SELECT first_name Name FROM student_details;&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
In the above query, the column first_name is given a alias as  &#39;name&#39;. So when the result is displayed the column name appears as  &#39;Name&#39; instead of &#39;first_name&#39;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Output:&lt;/b&gt; &lt;br /&gt;
&lt;span class=&quot;blue&quot;&gt; Name&lt;br /&gt;
-------------&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;green&quot;&gt; Rahul Sharma&lt;br /&gt;
Anjali Bhagwat&lt;br /&gt;
Stephen Fleming&lt;br /&gt;
Shekar Gowda&lt;br /&gt;
Priya Chandra&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;h3&gt;&amp;nbsp;&lt;/h3&gt;&lt;h3&gt;Aliases for tables:&lt;/h3&gt;&lt;code&gt;  SELECT s.first_name FROM student_details s; &lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
In the above query, alias &#39;s&#39; is defined for the table student_details and the column first_name is selected from the table.&lt;br /&gt;
Aliases is more useful when &lt;br /&gt;
&lt;ul&gt;&lt;li&gt; There are more than one tables involved in a query, &lt;/li&gt;
&lt;li&gt; Functions are used in the query, &lt;/li&gt;
&lt;li&gt; The column names are big or not readable, &lt;/li&gt;
&lt;li&gt; More than one columns are combined together&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://learninsql.blogspot.com/2012/01/sql-select.html&quot;&gt;&amp;lt;&amp;lt; Previous Chapter&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=&quot;http://learninsql.blogspot.com/2012/01/sql-where.html&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/a&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-alias.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-417663189252939050</guid><pubDate>Sat, 07 Jan 2012 05:57:00 +0000</pubDate><atom:updated>2012-01-09T01:44:24.231-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SQL SELECT</category><category domain="http://www.blogger.com/atom/ns#">SQL SELECT Statement</category><title>SQL SELECT</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;One of the most or one must say The most commonly used SQL command is the &lt;b&gt;SELECT&lt;/b&gt; statement. The SQL  SELECT statement is used to query or retrieve data from a table in the  database. A query may retrieve information from a specified column or  from all of the columns in the table. To create a simple SQL SELECT  Statement, you must specify the column(s) name and the table name. The  query as a whole is called SQL SELECT Statement.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;Syntax of SQL SELECT Statement:&lt;/h3&gt;&lt;code&gt; SELECT &lt;i&gt;column_list&lt;/i&gt; FROM &lt;i&gt;table-name&lt;/i&gt; &lt;br /&gt;
[WHERE Clause]&lt;br /&gt;
[GROUP BY clause]&lt;br /&gt;
[HAVING clause]&lt;br /&gt;
[ORDER BY clause];&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;i&gt;table-name&lt;/i&gt; is the name of the table from which you wish to retrieve the information.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;column_list&lt;/i&gt; includes one or more columns from which the data is retrieved.&lt;/li&gt;
&lt;li&gt;The code within the brackets is optional.&lt;/li&gt;
&lt;/ul&gt;&lt;b&gt;database table student_details;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;table border=&quot;0&quot; class=&quot;SQLTable&quot;&gt;&lt;tbody&gt;
&lt;tr bgcolor=&quot;#4284B0&quot;&gt;&lt;td&gt;&lt;b&gt;id&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;first_name&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;last_name&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;age&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;subject&lt;/b&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;games&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;&lt;td&gt;100&lt;/td&gt;&lt;td&gt;Saurabh&lt;/td&gt;&lt;td&gt;Sharma&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;Science&lt;/td&gt;&lt;td&gt;Cricket&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;&lt;td&gt;101&lt;/td&gt;&lt;td&gt;Anjali&lt;/td&gt;&lt;td&gt;Bhagwat&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;Maths&lt;/td&gt;&lt;td&gt;Football&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;&lt;td&gt;102&lt;/td&gt;&lt;td&gt;Stephen&lt;/td&gt;&lt;td&gt;James&lt;/td&gt;&lt;td&gt;09&lt;/td&gt;&lt;td&gt;Science&lt;/td&gt;&lt;td&gt;Cricket&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;&lt;td&gt;103&lt;/td&gt;&lt;td&gt;Shekar&lt;/td&gt;&lt;td&gt;Gowda&lt;/td&gt;&lt;td&gt;18&lt;/td&gt;&lt;td&gt;Maths&lt;/td&gt;&lt;td&gt;Badminton&lt;/td&gt;&lt;/tr&gt;
&lt;tr bgcolor=&quot;#CCCCCC&quot;&gt;&lt;td&gt;104&lt;/td&gt;&lt;td&gt;Priya&lt;/td&gt;&lt;td&gt;Chandra&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;Economics&lt;/td&gt;&lt;td&gt;Chess&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt;  These database tables are used here for better explanation of  SQL  commands. In reality, the tables can have different columns and  different data. &lt;/span&gt; &lt;br /&gt;
For example, consider the table student_details. To select the first name of all the students the query would be like:  &lt;br /&gt;
&lt;code&gt;  SELECT first_name FROM student_details;&amp;nbsp;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt;  The commands are not case sensitive. The above SELECT statement can also  be written as &quot;select first_name from students_details;&quot;&lt;/span&gt; &lt;br /&gt;
You can also retrieve data from more than one column. For example, to select first name and last name of all the students. &lt;br /&gt;
&lt;code&gt;  SELECT first_name, last_name FROM student_details; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
You can also use clauses like WHERE, GROUP BY, HAVING, ORDER BY with SELECT statement.  We will discuss these commands in coming chapters. &lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;black&quot;&gt;&lt;b&gt;NOTE:&lt;/b&gt;&lt;/span&gt;&lt;span class=&quot;note&quot;&gt; &lt;i&gt;In a  SQL SELECT statement only SELECT and FROM statements are mandatory.  Other clauses like WHERE, ORDER BY, GROUP BY, HAVING are optional.&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;note&quot;&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/span&gt; &lt;br /&gt;
&lt;h2&gt;How to use expressions in SQL SELECT Statement?&lt;/h2&gt;Expressions combine many arithmetic operators, they can be used in  SELECT, WHERE and ORDER BY Clauses of the SQL SELECT Statement.&lt;br /&gt;
&lt;br /&gt;
Here we will explain how to use expressions in the SQL SELECT Statement.  About using expressions in WHERE and ORDER BY clause, they will be  explained in their respective sections.&lt;br /&gt;
&lt;br /&gt;
The operators are evaluated in a specific order of precedence, when  more than one arithmetic operator is used in an expression. The order of  evaluation is: parentheses, division, multiplication, addition, and  subtraction. The evaluation is performed from the left to the right of  the expression.  &lt;br /&gt;
&lt;br /&gt;
For example: If we want to display the first and last name of an  employee combined together, the SQL Select Statement would be like &lt;br /&gt;
&lt;code&gt;  SELECT first_name || &#39; &#39; || last_name FROM  employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Output:&lt;/b&gt; &lt;br /&gt;
&lt;span class=&quot;blue&quot;&gt; first_name || &#39; &#39; || last_name&lt;br /&gt;
---------------------------------&lt;/span&gt; Saurabh &lt;span class=&quot;green&quot;&gt;Sharma&lt;br /&gt;
Anjali Bhagwat&lt;br /&gt;
Stephen James&lt;br /&gt;
Shekar Gowda&lt;br /&gt;
Priya Chandra&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;br /&gt;
You can also provide aliases as below.&lt;br /&gt;
&lt;code&gt;  SELECT first_name || &#39; &#39; || last_name AS emp_name FROM  employee; &lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Output:&lt;/b&gt; &lt;br /&gt;
&lt;span class=&quot;blue&quot;&gt; emp_name&lt;br /&gt;
-------------&lt;br /&gt;
Saurabh &lt;/span&gt;&lt;span class=&quot;green&quot;&gt;Sharma&lt;br /&gt;
Anjali Bhagwat&lt;br /&gt;
Stephen James&lt;br /&gt;
Shekar Gowda&lt;br /&gt;
Priya Chandra&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://learninsql.blogspot.com/2012/01/sql-commands.html&quot;&gt;&amp;lt;&amp;lt; Previous Chapter&lt;span style=&quot;color: blue;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/a&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;a href=&quot;http://learninsql.blogspot.com/2012/01/sql-alias.html&quot;&gt;&lt;span class=&quot;note&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-select.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4902137339535858867.post-7316114761754015288</guid><pubDate>Sat, 07 Jan 2012 05:38:00 +0000</pubDate><atom:updated>2012-01-09T01:33:44.706-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DCL</category><category domain="http://www.blogger.com/atom/ns#">DDL</category><category domain="http://www.blogger.com/atom/ns#">DML</category><category domain="http://www.blogger.com/atom/ns#">SQL Commands</category><category domain="http://www.blogger.com/atom/ns#">TCL</category><title>SQL Commands</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;SQL commands are instructions used to communicate with the database  to perform specific task that work with data. SQL commands can be used  not only for searching the database but also to perform various other  functions like, for example, you can create tables, add data to tables,  or modify data, drop the table, set permissions for users. SQL commands  are grouped into four major categories depending on their functionality:  &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;b&gt;Data Definition Language (DDL)&lt;/b&gt; - These SQL  commands are used for creating, modifying, and dropping the structure of  database objects. The commands are CREATE, ALTER, DROP, RENAME, and  TRUNCATE.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Data Manipulation Language (DML)&lt;/b&gt; - These SQL  commands are used for storing, retrieving, modifying, and deleting  data. These commands are SELECT, INSERT, UPDATE, and DELETE.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Transaction Control Language (TCL)&lt;/b&gt; - These SQL commands are used for managing changes affecting the data. These commands are COMMIT, ROLLBACK, and SAVEPOINT.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Data Control Language (DCL)&lt;/b&gt; - These SQL commands are used for providing security to database objects. These commands are GRANT and REVOKE.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span class=&quot;note&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &lt;a href=&quot;http://learninsql.blogspot.com/2012/01/sql-select.html&quot; style=&quot;color: blue;&quot;&gt;Next Chapter &amp;gt;&amp;gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;ul&gt;&lt;/ul&gt;&lt;/div&gt;</description><link>http://learninsql.blogspot.com/2012/01/sql-commands.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item></channel></rss>