0% found this document useful (0 votes)
8 views

select ,update command in sql.pptx

The document provides an overview of SQL commands, specifically focusing on the SELECT command and its various options, including filtering, ordering, and using operators like DISTINCT, IN, BETWEEN, and LIKE. It includes examples of SQL queries for retrieving and manipulating data in tables, as well as the UPDATE command for modifying existing records. The document serves as a guide for Class XI students in Informatics Practices to understand and apply SQL in database management.

Uploaded by

Anushka Rout
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

select ,update command in sql.pptx

The document provides an overview of SQL commands, specifically focusing on the SELECT command and its various options, including filtering, ordering, and using operators like DISTINCT, IN, BETWEEN, and LIKE. It includes examples of SQL queries for retrieving and manipulating data in tables, as well as the UPDATE command for modifying existing records. The document serves as a guide for Class XI students in Informatics Practices to understand and apply SQL in database management.

Uploaded by

Anushka Rout
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

SQL Commands

(Structured Query Language)

Informatics Practices
Class XI
Select : This command can be used to execute a query
and to retrieve information from one or more tables.
Format/Syntax:
select fieldnames
from < table name >
[where <condition>
order by <fieldname> [desc]
group by <fieldname>
having <condition> ];
Options with Select command
1. Use of *
2. Use of Distinct
3. Use of simple calculations
4. Use of where
5. Use of relational/logical operators
6. Use of in/between
7. Use of NULL
8. Use of wild card characters ( % and _ ) and LIKE keyword
9. Use of order by (asc-default / desc)
Options with Select command
1. Use of *
→Use of * with Select statement picks up all fields automatically for display.
2. Use of Distinct
→ Distinct Keyword:
By default, SQL shows all the data retrieved through query as output. However,
there can be duplicate values in a field. The SELECT statement when combined
with DISTINCT clause, returns values without repetition (distinct values) from a
particular field.
Syntax: Select distinct <fieldname> from<tablename>;
Note: Do not use any other fieldname or condition when using distinct
keyword.
Options with Select command
3. Simple calculations
→Using select we can do calculations too which may involve fields or
may not
Ex: Select 8*9+10;
Select name, sal, 0.50* sal, 0.30 *sal from emp
4. Use of where clause
→Where clause of select command is used to filter records from the
table. By filtering I mean, Selecting records based on a specified
condition.
Ex: Select * from emp where salary>45000;
Select * from emp where DOJ >”2004-01-30” and dept=“sales”;
SC INAME COST QTY DOPUR WARN Questions:
1 Carom 4000 20 27-Mar-98 3 1. Create the table.
2 Bat 10000 10 17-May-99 4 2. Insert the records
3 TTennis 8300 20 15-Apr-03 null 3. WAQ to display all records.
4 Pad 2150 10 23-Nov-91 4 4. WAQ to display item names along with cost for all items.
5. WAQ to Date of purchase and itemname.
5 Wicket 2500 10 07-Jun-93 3
6. WAQ to display the unique item names from the table.
6 Chess 2400 20 09-Aug-02 4 7. WAQ to display the name of items without repetition.
7 LTennis 25250 12 27-Mar-98 2 Use of Conditions:
8 Football 5450 20 07-Oct-92 3 8. WAQ to display the itemnames whose cost is more than 3000.
9 Hockey 5000 null 29-Mar-94 2 9. WAQ to display the code and itemnames which has been
10 Cork 300 10 01-Nov-01 null purchased after 1995 and cost <5000.
10. WAQ to display a report specifying itemname , cost and discount
Solutions: as 15% of price .Use column aliasing too.
3. Select * from item;
4. Select iname, cost from item; 10. Select iname, cost, 0.15*price AS “ Discount” from item ;
5. SELECT DOPUR, INAME FROM ITEM;
6, 7. Select distinct iname from item;
8. Select Iname from item where cost>3000;
9. Select sc,iname from item where DOPUR >’1995-12-31’ and cost <5000;
sc iname
1 Carom
2 Chess
3 Cork
Use of Membership Operator IN with Select Command
IN keyword with Select Command is used to specify or check for multiple values in a field.
The IN operator compares a value with a set of values and returns true if the value belongs to that set. It is
used in place of using the Logical OR operator.
Ex:
Select * from emp where dept IN(“admin”, ”sales”, ”Accounts”);

Select * from emp where dept =“admin” OR dept=“sales” OR dept=“Accounts”;

Advantage of using IN keyword in the above example lets us not to use the field name multiple times.
Use of Between keyword with Select Command
Between keyword with Select Command is used to specify a range of values in a field. It is used in place of
using the Logical AND operator
Ex:
Select * from emp where salary BETWEEN 5000 AND 15000;

Select * from emp where salary >= 5000 and salary <=15000;

Advantage of using BETWEEN keyword in the above example lets us not to use the field name multiple times.
Use of LIKE with Select Command
LIKE keyword is used to refer to a group of records (pattern matching) . We use 2 wild card characters to
create the group references:
Wild Card Characters are:
a) _ (underscore) : which refers to compulsory presence of a single character
b) % : which refers to presence of zero or more characters.

Example:
a) Names which starts with S and ends with A. S%A
b) Names which have T as the third character. _ _ T%
c) Names which end with Kapoor % Kapoor
d) Names which start with Anil. Anil%

Example of use of Like Operator:


1. WAQ to display the details of all employees whose department names start with A and have the fourth
character as i.
Ans: Select * from emp
where dept Like “A _ _ I”;

NOTE: DO NOT USE = (equal to sign) with LIKE Operator.


SC INAME COST QTY DOPUR WARN 7. WAQ to display the items whose warranty is in the range of 3
1 Carom 4000 20 27-Mar-98 3 to 5
2 Bat 10000 10 17-May-99 4 8. WAQ to display all details where cost is more than 5000 and
3 TTennis 8300 20 15-Apr-03 null less than 10000.
9. WAQ to display all details of Chess, football and Hockey.
4 Pad 2150 10 23-Nov-91 4
10. WAQ to display the unique QTY values.
5 Wicket 2500 10 07-Jun-93 3 11. WAQ to display the name,cost and qty for all those items
6 Chess 2400 20 09-Aug-02 4 whose cost >10000 and warranty is less than 3.
7 LTennis 25250 12 27-Mar-98 2 12. WAQ to display all details of items where warranty is not
8 Football 5450 20 07-Oct-92 3 given.
9 Hockey 5000 null 29-Mar-94 2 13. WAQ to display all details of those items where qty is
10 Cork 300 10 01-Nov-01 null mentioned
14. WAQ to display iname and DOPUR where costs are 4000 or
Solutions: 5000 or 8300 or 10000.
SC INAME COST QTY DOPUR WARN Write the SQL commands on the basis of
1 Carom 4000
Use
20 27-Mar-98
of Order3
By with Select Command
2 Order
Bat by 10000
Clause of10select command4is used to
17-May-99 tables
arrangeSPORTS.
the data in ascending or descending
3 order of the
TTennis 8300values
20of a15-Apr-03
particular field.
null ( a ) To list name and cost with their scode of those sports
4 PadDefault:
By 2150 10 23-Nov-91
the arrangement will be4 in ascending order.
which have been purchased after 13/10/98.
5 Wicket
If we want2500 10 07-Jun-93
to do it in desc order then 3
we use( bthe
) Tokeyword DESClisting number and name of the
display a report
6 Chess 2400 20 09-Aug-02 4 item in
7 LTennis 25250 12 27-Mar-98 2 ascending order cost where itemname starts with ‘C’.
8 Example:
Football 5450 20 07-Oct-92 3 ( c ) To display name of the item in reverse order where
9 Ques: WAQ to display
Hockey 5000 null 29-Mar-94 the name and2 salary of all employees in the ascending order of
scode is more than one.
10 salary.
Cork 300 10 01-Nov-01 null
( f ) To display the name of those items where either the
Ans: Select name, salary
warranty is less 2 years or the cost is more than 3000.
from emp
( g ) To display the cost and warranty of those which
order by salary.
have been purchased before 7th July 1997.
Ques: WAQ to display the name and salary of all employees in the descending order of
salary.
Ans: Select name, salary
from emp
order by salary desc;
update : This command can be used to update or modify values of
the rows in a table.
Syntax:
update <tablename>
set fieldname=<value> or <expression>
[where condition];
E.g.
(a) update student set city=‘Delhi’;
(b) update student set name=‘Kajal’, city =“NOIDA”
where roll>=2;
(c) update student set fee=fee+50
where stream=‘Commerce’;

You might also like