tag:blogger.com,1999:blog-49990248644929821832024-02-20T09:10:05.497-08:00SQL FundamentalsRamneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-4999024864492982183.post-47693297626379500502016-03-10T07:17:00.000-08:002016-03-10T07:17:12.477-08:00Select INTO<div dir="ltr" style="text-align: left;" trbidi="on">
Selects or copy the data from one table to another.<br />
<br />
<br />
Select * INTO EMP_DB2 From EMP_DATABASE; <br />
<br />
Copies the data from EMP_DATABASE to EMP_DB2<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-42596043621721880502016-03-10T07:10:00.002-08:002016-03-10T07:10:32.275-08:00Aliases Name<div dir="ltr" style="text-align: left;" trbidi="on">
The name given to the table or column for temporary result set.<br />
<br />
Example<br />
<br />
Select EMP_Name as Employee_Name From EMP_DATABASE;<br />
<br />
<br />
Select ABC.EMP_NAME From EMP_DATABASE as ABC;<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-85176701818254972082016-03-10T07:04:00.003-08:002016-03-10T07:04:40.190-08:00Between Operator<div dir="ltr" style="text-align: left;" trbidi="on">
Specifies the range and selects data within it.<br />
<br />
<br />
Select * From STUDENT_DATBASE<br />
Where Marks BETWEEN 20 AND 40;<br />
<br />
NOT keyword can also be used to exclude the range<br />
<br />
<br />
<br />
<br />
Select * From STUDENT_DATBASE<br />
Where Marks NOT BETWEEN 20 AND 40;</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-50217304677906592182016-03-10T06:57:00.002-08:002016-03-10T06:57:40.942-08:00IN Operator<div dir="ltr" style="text-align: left;" trbidi="on">
Multiple values can be specified with the Where clause<br />
<br />
Example<br />
<br />
Select * From EMP_DATABASE Where EMP_ID in ('AVX550', 'AV2551');</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-7714519759362551332016-03-10T06:52:00.001-08:002016-03-10T06:52:27.464-08:00Like Operator<div dir="ltr" style="text-align: left;" trbidi="on">
This operator can be use to search for specified pattern from data set.<o:p></o:p><br />
Example <o:p></o:p><br />
Select * From EMP_DATABASE Where EMP_Name LIKE 'R%'<o:p></o:p><br />
Displays the result where Employee name start with R alphabet<br />
<o:p></o:p><br />
Select * From EMP_DATABASE Where EMP_Name LIKE '%R'<o:p></o:p><br />
Displays the result where Employee name ends with R alphabet<br />
<o:p></o:p><br />
Select * From EMP_DATABASE Where EMP_Name LIKE '%R%'<o:p></o:p><br />
Displays the result where Employee name contains R alphabet<o:p></o:p><br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-5406663723299572612016-03-10T06:30:00.002-08:002016-03-10T06:30:33.053-08:00TOP Clause<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 115%; mso-fareast-font-family: "Times New Roman";">Limits the
number of Rows in the result set based on criteria or percentage specified</span><o:p></o:p><br />
<br />
<br />
Select TOP 3 * From EMP_DATABASE<br />
<br />
Select TOP 20 Percent * From EMP_DATABASE</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-19156560652869877522016-03-10T06:23:00.002-08:002016-03-10T06:23:54.663-08:00Delete Statement <div dir="ltr" style="text-align: left;" trbidi="on">
Delete statement allows you to delete rows from the existing table.<o:p></o:p><br />
Example<o:p></o:p><br />
Delete From EMP_DATABASE<o:p></o:p><br />
Where EMP_NAME ='Ramneek'<o:p></o:p><br />
To delete all records<o:p></o:p><br />
Delete * From EMP_DATBASE (Only Records deleted not Table)<o:p></o:p><br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-91897497013041852712016-03-10T06:18:00.001-08:002016-03-10T06:18:22.003-08:00UPDATE Keyword<div dir="ltr" style="text-align: left;" trbidi="on">
UPDATE keyword is used to update the records already in the database. Where caluse should always be specifed to update the existing record as this may even create column or data lock.<br />
<br />
Example<br />
<br />
Update EMP_Database<br />
Set EMP_NAME = 'Ramneek' <br />
Where EMP_NAME='Rakesh'<br />
<br />
<br />
This query will update EMP_NAME as Ramneek Where EMP_Name as Rakesh</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-42823470841520432122016-03-10T06:08:00.000-08:002016-03-10T06:08:41.412-08:00INSERT INTO<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
INSERT INTO allows you to enter new records in the Database.<o:p></o:p><br />
<br />
INSERT INTO EMP_DATABASE (EMP_NAME, EMP_ID) Values ('Ramneek','AVN7778');<o:p></o:p><br />
<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-42971577267174145472016-03-10T06:02:00.000-08:002016-03-10T06:02:03.330-08:00ORDER BY Keyword<div dir="ltr" style="text-align: left;" trbidi="on">
The keyword can be use to sort the result in ASC/DESC order. By Default the result is populated in ascending order.<br />
<br />
Select * From EMP_DATABASE ORDER BY EMP_NAME;<br />
<br />
Select * From EMP_DATABASE ORDER BY EMP_NAME DESC;<br />
<br />
Select * From EMP_DATABASE ORDER BY EMP_NAME ASC, EMP_ID DESC<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-32313427674244956642016-03-10T05:52:00.001-08:002016-03-10T05:52:34.359-08:00OR Keyword<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">This condition build the choice between two options by
specifying the OR keyword in the select statement.<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">Example<o:p></o:p></span></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<div class="MsoNoSpacing" style="margin: 0in 0in 0pt;">
<span style="font-family: Calibri;">Select * From EMP_Database Where EMP_NAME ='Ramneek' OR
EMP_NAME = 'Rakesh'<o:p></o:p></span></div>
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-45087853366803915722016-03-10T05:44:00.000-08:002016-03-10T05:44:50.777-08:00AND Keyword<div dir="ltr" style="text-align: left;" trbidi="on">
Specifies the selection with AND keyword in which both condition should be matching in the database.<br />
<br />
Example <br />
<br />
Select * From EMP_Database where EMP_Name='Ramneek' AND Place ='Gurgaon'<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-82664973940188486462016-03-10T05:38:00.003-08:002016-03-10T05:38:41.478-08:00Where Clause<div dir="ltr" style="text-align: left;" trbidi="on">
As the name specify. This keyword is used when we need to build query with spcific criteria.<br />
<br />
Example <br />
<br />
Select * From Table_Name Where EMP_ID =AVD330<br />
<br />
Select * From EMP_Database Where EMP_Name ="Ramneek Sharma"<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-19672429776822927532016-03-10T05:30:00.001-08:002016-03-10T05:30:24.446-08:00Distinct Keyword<div dir="ltr" style="text-align: left;" trbidi="on">
Distinct keyword allows you to get only different values from the database.<br />
<br />
Example<br />
<br />
Select DISTINCT Places from MaterTable_Database<br />
<br />
<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0tag:blogger.com,1999:blog-4999024864492982183.post-68492999050513992712016-03-10T05:21:00.003-08:002016-03-10T05:21:50.672-08:00Select Statement<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;">Select Statement is used to Pull/Fetch the data from
particular<span style="mso-spacerun: yes;"> </span>fields in a database.<o:p></o:p></span></div>
<span style="font-family: Calibri;">Example <o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 10pt;">
<span style="font-family: Calibri;">Select * From Table_Name;<span style="mso-spacerun: yes;">
</span>( * Retrieve all the columns from the Table)<span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<span style="font-family: Calibri;">Select<span style="mso-spacerun: yes;"> </span>EMP_ID,<span style="mso-spacerun: yes;"> </span>Contact_Details From EMPDatabase; ( Retrieves
Only Columns EMP_ID & Contact_Details from EMPDatabase Table)<o:p></o:p></span><br />
<br />
<br />
<br />
</div>
Ramneek Sharma - VBA/Data Extraction/Automation/MIShttp://www.blogger.com/profile/03940798798101225006noreply@blogger.com0