SlideShare a Scribd company logo
8SQL SERVER: RETREIVINGDATA FROM A DATABASE
Retrieving Data from DatabaseHow to retrieve data from the given database?After creating the database structure, customizing it to fit the needs and feeding it with data, the next step is to retrieve required data for performing various operations.So how do we get these data?The answer:			Just like in English language, Microsoft SQL Server also provides us the basic keyword for retrieval of data called “Select”SELECT
Select SyntaxThe Syntax of the select statement is simple:The basic syntax for this DML ( Data manipulation Language) command is select <fieldName1, fieldName2,…> from <table name>;This will select the appropriate columns for the given table.  As it is a DML command, it is not necessary to use the keyword TABLE(,as in ‘alter table’)
Displaying the entire tableWhat if it is needed to display all the columns?The Syntax is:select * from tablename;‘*’, the most widely used wildcard comes to our aid. Isn’t it much better than remembering all the column names.Example: select * from student; displays the entire student table
Selecting selective recordsHow to display only certain rows containing the appropriate column?SQL Server answers this question with two simple commands: where
likeselect * from tablename where <conditions>;select * from tablename where fieldNamelike <conditions>;
LIKE explainedSQL Command:Select * from cartoon	where cartoonName like ‘Laughs and Gags’The Where clause: Where is used to specify a condition for the Query
 For string matching, use the ‘like’ keyword. Here, wild card characters(% and _)% -character represents a group(or single) of characters _ -character represents a single characterIllustration:To Update cartoons whose names start with the letter ‘a’ must be given as Update cartoon set rating=100 	where cartoonName = ‘a%’
LIKE explainedIllustration:To Update cartoons whose names start with the letter ‘a’ and the name must of 3 characters in length:Update cartoon set rating=100 	where cartoonName = ‘a__’
Filter-out duplicate selectionsNow, we have a problem. What if there are two records have the same data? The select command will select both the records. To avoid this the distinct keyword is used.select distinct <col> from tablename;Note:	Use distinct only for a single column.
Grouping of recordsIn SQL, it is possible to group records based on the values of a particular field.Syntax:Select * from <tableName> group by <fieldName>;Example: To display the details of students, grouped based on their class, the command will be:Select * from student group by class;
Ordering of recordsIn SQL, it is possible to sort records based on the values of a particular field.Syntax:Select * from <tableName> order by <fieldName>;Example: To display the details of students, sorted based on their GPAs, the command will be:Select * from student order bygpa;The default ordering is ascending in nature. To make it into descending, use the desc keyword. Eg:Select * from student order bygpadesc;

More Related Content

PPTX
MS Sql Server: Feeding Data Into Database
PPT
ALL ABOUT SQL AND RDBMS
PPTX
Retrieving Data From A Database
PPT
Advanced Sql Training
PPTX
STRUCTURE OF SQL QUERIES
PPTX
Sql basics
PDF
Chapter8 my sql revision tour
MS Sql Server: Feeding Data Into Database
ALL ABOUT SQL AND RDBMS
Retrieving Data From A Database
Advanced Sql Training
STRUCTURE OF SQL QUERIES
Sql basics
Chapter8 my sql revision tour

What's hot (16)

PPTX
Data Manipulation Language
PPTX
Lab1 select statement
PPTX
Sql.pptx
DOC
PPT
SQL DDL
PPT
Sql select
PPT
Introduction to-sql
PDF
Chapter9 more on database and sql
PPTX
Advanced SQL Webinar
PPTX
Introduction to SQL
PPTX
Where conditions and Operators in SQL
PPT
Les02 (restricting and sorting data)
PPTX
Database Management - Lecture 2 - SQL select, insert, update and delete
ODP
PDF
Nested Queries Lecture
Data Manipulation Language
Lab1 select statement
Sql.pptx
SQL DDL
Sql select
Introduction to-sql
Chapter9 more on database and sql
Advanced SQL Webinar
Introduction to SQL
Where conditions and Operators in SQL
Les02 (restricting and sorting data)
Database Management - Lecture 2 - SQL select, insert, update and delete
Nested Queries Lecture
Ad

Similar to MS SQL SERVER: Retrieving Data From A Database (20)

DOC
Introduction to sql
DOCX
Learning sql from w3schools
PPTX
DOCX
SQL Language
PDF
SQL Basics and Advanced for analytics.pdf
PDF
SQL_BASIC AND ADVANCED.pdf
DOCX
DOC
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
PDF
SQL-Notes.pdf mba students database note
PPTX
2 puc cs.pptx bsbshsjshsbbsjsjshdbdbbdbdd
PPTX
XII_IP_PPT[2].pptxhggggggggggggggggggggggggggggggggdj
PDF
PPT
SQL || overview and detailed information about Sql
PPT
CE 279 - WRITING SQL QUERIES umat edition.ppt
PPTX
SQL Tutorial for Beginners
PDF
full detailled SQL notesquestion bank (1).pdf
PDF
SQL notes 1.pdf
PDF
Oracle Notes
PDF
Basic sqlstatements
PDF
Chapter – 6 SQL Lab Tutorial.pdf
Introduction to sql
Learning sql from w3schools
SQL Language
SQL Basics and Advanced for analytics.pdf
SQL_BASIC AND ADVANCED.pdf
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
SQL-Notes.pdf mba students database note
2 puc cs.pptx bsbshsjshsbbsjsjshdbdbbdbdd
XII_IP_PPT[2].pptxhggggggggggggggggggggggggggggggggdj
SQL || overview and detailed information about Sql
CE 279 - WRITING SQL QUERIES umat edition.ppt
SQL Tutorial for Beginners
full detailled SQL notesquestion bank (1).pdf
SQL notes 1.pdf
Oracle Notes
Basic sqlstatements
Chapter – 6 SQL Lab Tutorial.pdf
Ad

More from sqlserver content (20)

PPTX
MS SQL SERVER: Using the data mining tools
PPTX
MS SQL SERVER: SSIS and data mining
PPTX
MS SQL SERVER: Programming sql server data mining
PPTX
MS SQL SERVER: Olap cubes and data mining
PPTX
MS SQL SERVER: Microsoft time series algorithm
PPTX
MS SQL SERVER: Microsoft sequence clustering and association rules
PPTX
MS SQL SERVER: Neural network and logistic regression
PPTX
MS SQL SERVER: Microsoft naive bayes algorithm
PPTX
MS SQL SERVER: Decision trees algorithm
PPTX
MS SQL Server: Data mining concepts and dmx
PPTX
MS Sql Server: Reporting models
PPTX
MS Sql Server: Reporting manipulating data
PPTX
MS Sql Server: Reporting introduction
PPTX
MS Sql Server: Reporting basics
PPTX
MS Sql Server: Datamining Introduction
PPTX
MS Sql Server: Business Intelligence
PPTX
MS SQLSERVER:Feeding Data Into Database
PPTX
MS SQLSERVER:Doing Calculations With Functions
PPTX
MS SQLSERVER:Deleting A Database
PPTX
MS SQLSERVER:Customizing Your D Base Design
MS SQL SERVER: Using the data mining tools
MS SQL SERVER: SSIS and data mining
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Olap cubes and data mining
MS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Neural network and logistic regression
MS SQL SERVER: Microsoft naive bayes algorithm
MS SQL SERVER: Decision trees algorithm
MS SQL Server: Data mining concepts and dmx
MS Sql Server: Reporting models
MS Sql Server: Reporting manipulating data
MS Sql Server: Reporting introduction
MS Sql Server: Reporting basics
MS Sql Server: Datamining Introduction
MS Sql Server: Business Intelligence
MS SQLSERVER:Feeding Data Into Database
MS SQLSERVER:Doing Calculations With Functions
MS SQLSERVER:Deleting A Database
MS SQLSERVER:Customizing Your D Base Design

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
cuic standard and advanced reporting.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Encapsulation theory and applications.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
cuic standard and advanced reporting.pdf
Empathic Computing: Creating Shared Understanding
Advanced methodologies resolving dimensionality complications for autism neur...
MYSQL Presentation for SQL database connectivity
Encapsulation theory and applications.pdf
Assigned Numbers - 2025 - Bluetooth® Document
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Programs and apps: productivity, graphics, security and other tools
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...

MS SQL SERVER: Retrieving Data From A Database

  • 2. Retrieving Data from DatabaseHow to retrieve data from the given database?After creating the database structure, customizing it to fit the needs and feeding it with data, the next step is to retrieve required data for performing various operations.So how do we get these data?The answer: Just like in English language, Microsoft SQL Server also provides us the basic keyword for retrieval of data called “Select”SELECT
  • 3. Select SyntaxThe Syntax of the select statement is simple:The basic syntax for this DML ( Data manipulation Language) command is select <fieldName1, fieldName2,…> from <table name>;This will select the appropriate columns for the given table. As it is a DML command, it is not necessary to use the keyword TABLE(,as in ‘alter table’)
  • 4. Displaying the entire tableWhat if it is needed to display all the columns?The Syntax is:select * from tablename;‘*’, the most widely used wildcard comes to our aid. Isn’t it much better than remembering all the column names.Example: select * from student; displays the entire student table
  • 5. Selecting selective recordsHow to display only certain rows containing the appropriate column?SQL Server answers this question with two simple commands: where
  • 6. likeselect * from tablename where <conditions>;select * from tablename where fieldNamelike <conditions>;
  • 7. LIKE explainedSQL Command:Select * from cartoon where cartoonName like ‘Laughs and Gags’The Where clause: Where is used to specify a condition for the Query
  • 8. For string matching, use the ‘like’ keyword. Here, wild card characters(% and _)% -character represents a group(or single) of characters _ -character represents a single characterIllustration:To Update cartoons whose names start with the letter ‘a’ must be given as Update cartoon set rating=100 where cartoonName = ‘a%’
  • 9. LIKE explainedIllustration:To Update cartoons whose names start with the letter ‘a’ and the name must of 3 characters in length:Update cartoon set rating=100 where cartoonName = ‘a__’
  • 10. Filter-out duplicate selectionsNow, we have a problem. What if there are two records have the same data? The select command will select both the records. To avoid this the distinct keyword is used.select distinct <col> from tablename;Note: Use distinct only for a single column.
  • 11. Grouping of recordsIn SQL, it is possible to group records based on the values of a particular field.Syntax:Select * from <tableName> group by <fieldName>;Example: To display the details of students, grouped based on their class, the command will be:Select * from student group by class;
  • 12. Ordering of recordsIn SQL, it is possible to sort records based on the values of a particular field.Syntax:Select * from <tableName> order by <fieldName>;Example: To display the details of students, sorted based on their GPAs, the command will be:Select * from student order bygpa;The default ordering is ascending in nature. To make it into descending, use the desc keyword. Eg:Select * from student order bygpadesc;
  • 13. Summary8. Retrieving data from a database: Select Syntax
  • 18. Order byVisit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net