Home Blog Page 2

Learn Microsoft SQL Server SELECT And ORDER By Clauses- Section4


Learn Microsoft SQL Server SELECT And ORDER By Clauses. How to learn sql server?

Well come to Section 2 in this section we’ll be discussing about select an order by clauses two of the major causes in C will discuss how to use a bezique select clothes how to select or columns how to select some or all columns using column names in your column headings how to perform mathematical oppression how to use system functions.

We’ll also see what conditional evaluation looks like in silly clothes.We’ll see how to select top end values how to filter duplicates how to use basic order by clause. Finally we’ll discuss about exercise questions for the D.S..

 How to use a basic SELECT clause?

We are back to see concert Management Studio Now if you want to follow along you should be able to find lectures to see fall in resources folder for. Let’s first see what the bezique select clause looks like. Let’s change our data is context. CIA factbook DV. Select can be used or the FROM clause to select a number or string. Or at least Trotz.

We’ll see what the FROM clause and what it’s going to help us in a cabbing sections. So look the number literally like the one you see some like 100 or any decimal point like one hundred point ninety eight. You can’t just simply type select plus the number that you want to select. Next you’ll select the query that you want to execute.

As we’ve discussed previously and you click on execute you’ll see the column being selected with 100 9 8 and no column name is available. If you want to provide a column name to little you just selected you can use is reserved for word and this is number. Now if it’s like the column heading will be this is the number and the value of the column only has one recurved.


One hundred ninety eight if you want to select a string or it takes like here it just can’t tie the string itself. It has to be called. Inside a single call. So if I execute this war you see that the string literal We need that single quarter around the text that you’re selecting the same thing goes for dates. If you only select a date literal it has to be quarter to each side a single called like the one you see here how ever if I don’t have that inside a single code sequence server simply returns 0.

How to select all columns ?

In this movie we’ll discuss how this works. All columns and rows from a table we have a fully dedicated section for of course what the FROM clause does is it’s going to help us to reference tables or a subset select statements. To rephrase that so that we can be able to carry combs in the subjects that might if you like to query all in rows and columns form a table you can simply type select stories from a table.

We have a table called country here and if we want to see all columns and all the rules from a table called country we can’t see this. However in production environment this is not recommended as a table could have a lot of rows and columns and it might slow down an hour or so. But in a development environment this will help us see what their rows and columns of a table look like.

In the previous Paragraph we’ve seen how we can be able to select all columns from a table for example from a country we simply did select stories from a country and we were able to see all the columns and all the rows from that table in this movie. Let’s see how we can be able to project or see only some of the columns from that table as well as how we can only be able to filter and see some of the top values of that table.

We only want to see the name of the country and its population size we can specify the column names and we can execute. Now we’re only going to be seeing these two columns on the table next. Let’s look at how we can only be able to see only the top and the values of that tape for example are here to see only the top five by use from a table called for then we can use a top function.

A function can be a top and a number or we can use a top inside Apprentice’s. Now this will become a national function that we can pass a parameter from a procedure to it. Now if I execute this one it’s going to show me only the top five values from a table Weaver.


How to filter duplicate in SELECT clause? Section7

How to filter duplicate in SELECT clause

In the previous article we’ve seen how we can be able to implement cange Ivo issuing this statement. We’ve also seen examples using kids when as well as I say in this article we’re going to continue our discussion by looking at filtering in duplicate and a select statement. Let’s see one example here.

When you are working at least you might have to create some reports that is not going to contain any duplicate file use we’re acquiring these Montane table for example you can see a mounted and Rocky’s duplicate that more than 10 times a year. The simplest way for us to filter out this duplicate is using a keyword called District files.

The same query that has this thing. Now you can see that Rocky Mount is only going to appear once. Another way to do it is using a pie so we can get rid of it distinct. But if you use the same columns that we use in the select statement in the group why close that is going to give us the same thing or use as well.

How to use a basic ORDER BY clause?

It the previous movies we’ve discussed about select statement in a sequence of which we’ve seen a basic select statement the sequel. We discuss how we can be able to manage plate number treeing and deathly Trotz. We’ve also discussed how we can be able to carry columns from a table how we can be able to perform some condition.

I’ve always been using this way in as well as functions how we can be able to perform some mathematical operations as well as how we can be able to use some building function inside a select state.


In this article we’ll discuss about order by a cause. Another important state and one in sequent language. Let’s assume we’re working as and at least we were tasked to create a report that is going to follow some sort of an order and to be able to produce these. We’re going to have to implement an ORDER BY clause. There are two kinds of order. There is ascending order.

Then we have to use a s c then b a descending order or D s c a d forth ordering. If we don’t specify an ascending order then if I execute this statement you will see that the state I said is order. Yes and the order population. ORDER BY clause we can also be able to sort using two or more columns for example.

We will like to order Montaigne’s by name then by their elevation in a descending order if I execute this statement you will see that this data is sorted by name first and then by elevation.For example if we look at Rocky Mountains you’ll see that the top peak of the mountain or Moland elbow comes first then the second topic of Montaigne’s which is peaks Pike comes back to the status it is or it is Montaigne’s in ascending form and then with elevation in the informant.

So you can keep adding more columns as you wish for an order by clause. Another way to do an ordering is you can be able to refinance the column order Montaigne’s. The second call on the select statements so this. What this means is use mandis for your first ordering in an ascending format and use elevation on the third column.

This is not recommended practice in production but when you are doing any testing you can quickly type the number to be able to sort but another developer columns here then your orders will not be the same. If you’re using an order number instead of a column name or order by.


Conditional evaluations in SELECT clause – Section6


In the previous article we discuss about pre-build function in sequels or as well as how we can be able to implement them in a select statement. In this movie we’ll discuss how to use a conditional evaluation in a select statement.There are two ways how we can be able to implement conditionally volition select statement the original way how we can be able to do that was using kids when a statement will do case when an evaluation of some sort.

Then what should be the result of that evaluation should it be. And we can repeat a when and then for different conditions. Finally we can put the else statement what should happen if any of the previous conditions are not being met. In a recent version of sequencer Microsoft added this I function. I have some condition this will be a true evaluation. Or what should happen if this is true. Else what should we display.


If this is wrong or false of secure this one one is greater than zero. Then this statement will be executed. Then we’ll see here a greater Also if we execute. This is the atom. I have zero craters on one. This is not true than these Vayu or a laser or be executed said use in a case where or if statement for a string or number literals like the one we did it before we can also be able to implement it in a select statement that is queering from a table or a data set.

For example we are tasked to categorize and c reate.You can create a column called economics that is based on a GDP that have greater than 300 billion to be locked and everything else to be called. Give a little peek. If we execute the sequence statement we’ll see. For Australia it has more than three hander which is four hundred seventeen billion GDP so that it’s categorized as developed here.

But if we look at Afghanistan here it only has 20 billion of GDP so that it was categorized as terrible pink. We can also be able to add additional conditions here. For example if we first categorize this one case when GDP greater than 300 to be called developed in any country that has between 200 and 300 to be called Dave or pink and everything else to be underdeveloped now free execute the select statement again we’ll see Australia being developed.

We haven’t changed any condition on that one. Afghanistan will see under a lot of our GDP is not between a hundred and 300. And you might see other countries like here that’s going to say that the lopin its annual GDP is two hundred forty three billion dollars.


How to change column headings and perform mathematical operations in SELECT? Section5

How to change column headings and perform mathematical operations in SELECT?

In the previous article we’ve seen how we can be able to project or display all these columns from a table as well as how we can be able to display only the top end rolls from a table in this movie you will see how we can be able to change a column hitting inside a select statement and how we can be able to perform some mathematical operation using columns is a select state.

I will also give you some overview of what mathematical operations or functions looks like inside a select statement. In this example some experts predicted that a population of every country in the world will be increasing by a million people in the next five years. And you are asked to call it final. Population value. Thirty five years. In this case what you can do is you can use a select statement a name of a country and our population size plus one million from country.

If you execute the sequence statement without using a column heading you’ll get a name like Australia Afghanistan and other countries. But for the newly created you not have any money in order to give it a column heading for I knew would call quited Cole and you can do as an economy now if execute the sequence statement. It’s going to give me a name of a country as well as the projected population besides using some simple mathematical operation like this.

Once the calls are also has some pre-built functions like this for example. In this case we want to calculate the total area in a row of every lake in the world that we can execute this one. This is going to be our total area in an average area of every link in the world. SQL Server also follows a mathematical rule or Mars or Rockett older division multiplication by addition and subtraction.

Like for example in this case we have two plus three times for the result. Could it be two plus 3 which is 5 5 times 4 which is 20. But because of bored us sequel server won’t finish multiplication ahead of time then it’s going to be three times four. Which is 12 plus 2. It is 14. So if we execute this month then we’ll get 14. But if we want to change how this operation works and we want to add two and three fourths then multiply it by 4.

We can use a bracket since the bracket comes first. The important rule then this will be calculated ahead of time. Then the result will be multiplied by four. Two plus three will be five lifetimes or is going to be 22. Now if I execute this statement I’ll get twenty.