06.01 sql select distinct
Upcoming SlideShare
Loading in...5

06.01 sql select distinct






Total Views
Views on SlideShare
Embed Views



4 Embeds 6

http://www.facebook.com 3
https://www.facebook.com 1
https://m.facebook.com&_=1370512979775 HTTP 1
https://m.facebook.com&_=1370524469016 HTTP 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

06.01 sql select distinct 06.01 sql select distinct Presentation Transcript

  • SQL SELECT DISTINCTStatement In a table, some of the columns may containduplicate values. This is not a problem,however, sometimes you will want to list onlythe different (distinct) values in a table. The DISTINCT keyword can be used to returnonly distinct (different) values. SQL SELECT DISTINCT SyntaxSELECT DISTINCT column_name(s)FROM table_name
  • SELECT DISTINCT Person.PNameFROM Person;Id Name Address Hobby1123 Anita Damauli stamps1123 Anita Damauli coins5556 BinodKathmanduhiking9876 BarshaKathmandustampsPNameAnitaBarshaBinod
  • SQL AND & OR Operators The AND & OR operators are used to filterrecords based on more than one condition The AND operator displays a record if both thefirst condition and the second condition aretrue. The OR operator displays a record if either thefirst condition or the second condition is true.
  • SQL OR OperatorsSELECT * FROM PersonWHERE Person.Hobby=hiking ORPerson.ID>3000;ID PName Address Hobby5556 Binod Kathmandu hiking9876 Barsha Kathmandu stamps
  • SQL AND OperatorsSELECT *FROM PersonWHERE Person.ID>3000 AND Person.ID<5999;ID PName Address Hobby5556 Binod Kathmandu hiking
  • SQL ORDER BY The ORDER BY keyword is used to sort theresult-set. The ORDER BY keyword is used to sort theresult-set by a specified column. The ORDER BY keyword sorts the records inascending order by default. If you want to sort the records in a descendingorder, you can use the DESC keyword.
  • SQL ORDER BY Syntax SELECT column_name(s)FROM table_nameORDER BY column_name(s) ASC|DESCSELECT Person.HobbyFROM PersonORDER BY Person.Hobby;Hobbycoinshikingstampsstamps
  • SQL INSERT INTO The INSERT INTO statement is used to insert a newrow in a table.SQL INSERT INTO Syntax It is possible to write the INSERT INTO statement intwo forms. The first form doesnt specify the column nameswhere the data will be inserted, only their values:INSERT INTO table_name VALUES (value1, value2,value3,...) The second form specifies both the column namesand the values to be inserted:INSERT INTO table_name (column1, column2, column3,...)VALUES (value1, value2, value3,...)
  • SQL INSERT INTO INSERT INTO PersonsVALUES (4,Nilsen, Johan, Bakken 2,Stavanger) INSERT INTO Persons (P_Id, LastName,FirstName)VALUES (5, Tjessem, Jakob)
  • SQL UPDATEThe UPDATE statement is used to updateexisting records in a table.SQL UPDATE Syntax:UPDATE table_nameSET column1=value, column2=value2,...WHERE some_column=some_valueExample:UPDATE PersonsSET Address=‘Nayabazar, City=‘KathmanduWHERE LastName=‘Ghimire ANDFirstName=‘Bishal
  • SQL UPDATE Warning Be careful when updating records. If we hadomitted the WHERE clause in the exampleabove, like this:UPDATE PersonsSET Address=‘Nayabazar, City=‘Kathmandu‘What will be the result ?
  • SQL DELETE The DELETE statement is used to delete rowsin a table.SQL DELETE SyntaxDELETE FROM table_nameWHERE some_column=some_valueDELETE FROM PersonsWHERE Address=‘Nayabazar, City=‘Kathmandu‘
  • SQL TOP The TOP clause is used to specify the numberof records to return. The TOP clause can be very useful on largetables with thousands of records. Returning alarge number of records can impact onperformance. Note: Not all database systems support theTOP clause. SQL Server Syntax SELECT TOP number|percent column_name(s)FROM table_name
  • SQL TOP MySQL Syntax SELECT column_name(s)FROM table_nameLIMIT number Oracle Syntax SELECT column_name(s)FROM table_nameWHERE ROWNUM <= number SELECT * FROM Persons LIMIT 5
  • SQL LIKE The LIKE operator is used to search for aspecified pattern in a column. SQL LIKE Syntax SELECT column_name(s)FROM table_nameWHERE column_name LIKE pattern
  • SQL LIKE To select the persons living in a city that startswith "s" from the table. SELECT * FROM PersonsWHERE City LIKE ‘k%
  • SQL WildcardsWildcard Description% A substitute for zero or more characters_ A substitute for exactly one character[charlist] Any single character in charlist[^charlist]or[!charlist]Any single character not in charlist• SQL wildcards can substitute for one or morecharacters when searching for data in adatabase.• SQL wildcards must be used with the SQLLIKE operator.
  • SQL IN The IN operator allows you to specify multiplevalues in a WHERE clause. SQL IN Syntax SELECT column_name(s)FROM table_nameWHERE column_name IN (value1,value2,...)
  •  Example #1Select *From AddressWhere FirstName IN (Mary, Sam) Example #2SELECT *FROM AddressWHERE FirstName = MaryOR FirstName = Sam
  • SQL BETWEEN The BETWEEN operator selects a range ofdata between two values. The values can benumbers, text, or dates. SQL BETWEEN Syntax SELECT column_name(s)FROM table_nameWHERE column_nameBETWEEN value1 AND value2
  •  Example: SELECT * FROM suppliers WHERE supplier_idBETWEEN 5000 AND 5010; SELECT * FROM suppliers WHERE supplier_id>= 5000 AND supplier_id <= 5010;
  •  example: SELECT * FROM orders WHERE order_datebetween to_date (2013/01/01, yyyy/mm/dd)AND to_date (2013/12/31, yyyy/mm/dd); SELECT * FROM orders WHERE order_date >=to_date(2013/01/01, yyyy/mm/dd) ANDorder_date <=to_date(2013/12/31,yyyy/mm/dd);