
Well, we can use the Count() function in conjunction with Distinct() Now, what if you want to know how many distinct job titles exist in the company. Placing the column you want in the parenthesis and the query will return a non repeating list. In this case, you will use the Distinct() function. What if you wanted a list of job titles without any repeating elements. Notice how there are repeated JobTitles in the table below. If you wanted to know how many male employees are in the table, you can add a Where clause (I will cover Where more in-depth in later lessons) This returns the number of records in the table. If yon want a count of the number of records in a table, SQL has a Count() function. If I wanted to go the other way, I would use the command: order by HireDate asc – ascending(asc) Count() The order by command sorts the results by the dates in the column HireDate in descending order (desc) most recent to earliest. If you want to top 10 newest employees you would need to add an Order By command. Note that the query above returns the first 10 records based usually on the order records were entered. Using Select * in some larger tables without using the Top command to limit the amount of output can result in a query that could take minutes to hours to complete. This is often useful when you are exploring a database and just want to see what is in a table. Using Top 10 we are querying only the first 100 records from the Employee table. (note Top is a T-SQL (Microsoft’s version of SQL command. Top allows you to limit the number of rows that are returned.
1983 malayalam movie songs how to#
If you want to follow along with the exercises, go to my previous SQL posting: SQL: SELECT Statement where I show you how to download and attach the AdventureWorks2012 database. **note, in the examples below, I am working with the HumanResources.Employee table from the AdventureWorks2012 data set. Now I am going to show you some tricks that will provide you with more functionality in your Select statements. I introduced you to the SELECT statement in SQL in my last SQL posting: SQL: SELECT Statement If you enjoyed this lesson, click LIKE below, or even better, leave me a COMMENT.įollow this link for more SQL content: SQL Where (MaritalStatus = ‘M’ and Gender = ‘M’) or JobTitle like ‘Tool Designer’ This query returns all Married Males as well as all Tool Designers regardless of gender or marital status. They state that the items inside must performed first. Parenthesis are used just like your remember from Algebra class. Where MaritalStatus = ‘M’ or Gender = ‘F’ This returns all employees who are married or employees who are F regardless of martial status Where MaritalStatus = ‘M’ and Gender = ‘F’ This query returns all Married employees who are Female The Between keyword can used to find records that fall between 2 values When trying to search by part of a string, we use the % wildcard.Ĭonsider the sentence “Dogs love chasing cats”īelow we use a wildcard to find all job titles that end in Engineer

To find a string value, we are going to use the Like keyword: Where Field like ‘String’ To find a single matching numeric field, use Where Field = Number Let’s use Where to find the record with the BusinessEntityID of 6:įROM. We are going to be using some selected fields from the table HumanResouces.Employee in the AdventureWorks2012 database. Instructions for loading Adventure Works: SQL: SELECT Statement MS SQL Server installation instructions here: MS SQL Server: Installation

If you want to follow along with the exercises:
1983 malayalam movie songs free#
In this lesson we will be using MS SQL Server and Microsoft’s free database example Adventure Works 2012. The Where clause in SQL works as a filter.
