The Ultimate SQL Course for Beginner's to Advanced- 2023

The Ultimate SQL Course for Beginner's to Advanced- 2023

Ashutosh Kumar

0:00 hello everyone welcome back to my YouTube channel this is a very special

0:04 video into this particular video I've covered

0:06 almost all the concepts from the very

0:09 basic level to the advanced level which are required to crack any

0:13 of the top interview roles for any analyst position in the top mncs

0:19 as well as the startups so friends into this particular video we'll be

0:23 starting from the very fundamental level about learning what is a database then

0:28 we'll go on to create our database we'll be starting to learn about

0:31 the crowd operation into the next section we'll be learning about the different

0:35 type of functions which are present into the SQL such as the string

0:40 functions the numeric function the date time functions as well so we have

0:44 covered the Aggregates as well as how the group by function Works how

0:49 the having function Works into this SQL these form the most important part

0:54 of any SQL interview because these are some of the concepts which are

0:58 used a lot of many times into the day really work so friends

1:01 then we'll be moving to the most important part of the sequel which

1:05 are the SQL joins I've discussed all of these Concepts how they internally

1:10 function I've covered them into as much

1:13 as detail as possible into the description

1:16 box of this particular video I have attached the link of all

1:21 the resources which have utilized while explaining all the concepts also you

1:26 can find the timestamp and you can jump off to any time stamp

1:30 on any concept which you want to learn so friends if you will

1:34 find this video helpful don't forget to hit the like button and also

1:38 subscribe to my channel if you haven't to receive such kind of useful

1:41 information on a regular basis without wasting much time let us quickly move

1:46 to our screen and start onto the Journey of learning SQL and let

1:53 us start from the very basic thing which is the database now what

1:57 is database so in simple words a database is an organized collection of data

2:02 stored small databases can be stored on a file system while large databases

2:07 are hosted on computer clusters or cloud storage so I have copied

2:12 the same definition which is present onto the Google so when you will be

2:16 Google searching for what is a database we'll be getting the exact definition

2:21 and this definition is very much simple to understand so friends in simple words

2:25 a database is an organized collection of data so what does this organized

2:29 collection of data mean so friends if you remember if I make you

2:32 understand in very simple terms if you remember in school or college days

2:35 we were having this attendance register

2:38 where uh professors or our teachers would

2:41 maintain whether we were present or absent on a certain day so

2:46 friends this is also a kind of data which is being stored about

2:49 the attendance of the students the other kind of an example which I

2:53 could provide a very simple example was before mobile phone came into picture we

2:58 were having this telephone directory

3:00 in our house where everybody's our relatives friends

3:03 we were having their name and we were having their phone number also

3:07 attached so friends this is also a simple kind of data which we

3:11 are storing students likewise a database can

3:13 be considered as such kind of organized

3:16 collection of data which is being stored and which will be used

3:19 for different purpose so let's quickly move to the next screen so that it

3:23 is very much clear for you I have many examples ready here

3:28 for you to make you understand what our database so very first example you

3:32 can see here the attendance register which I was talking about also

3:35 into the very first column you can see the different student IDs which are

3:38 present here so let us say the student ID is S1 H2 S3

3:42 and these I'm into the particular row you can see we have different

3:47 dates which are present here and on into all of these section we

3:52 have the information whether the student was present or the student was absent

3:56 so this is an organized collection of the data which is being stored

3:59 so this can be considered as the students uh you know attendance database

4:03 similarly let's say this another example here which is of the product inventory

4:08 into the very first column we have the product and we have IDs

4:12 into the second column we have their quantity into the third column we

4:16 have the price the fourth column we have number of quantities which are

4:20 into the packing section into the fifth

4:22 column we have information about the number

4:25 of units which are into the shipping uh section and into the last

4:30 column we have number of units which are delivered so friends we have

4:34 all this information arranged into an organized way and this can be considered

4:39 as a product inventory you know data based similarly into the cricket we

4:44 have the players the runs which have been scored by them the wickets

4:47 that our players have taken and the catches they have taken so this is

4:51 also a kind of organization which we are storing here and the very

4:55 last is the example which I gave where we had different people

4:59 uh telephone number which we were writing it down into our telephone directory

5:04 into the earlier days so friends this is also an example of the simple

5:07 data which is being stored into an organized way let us move

5:11 to the next section I hope this is pretty much clearer what

5:15 is a data base now friends okay we have saw from the definition

5:21 that we came to the previous time we were storing the small information

5:26 uh into a pi system as you can see here small databases can be

5:31 stored on a file system while large databases are hosted on a computer

5:35 cluster now why do why do we require the need of storing data

5:40 onto the cloud or onto the computer let's understand with an example

5:44 of a company so swiggy is online food delivery company in India so what why

5:51 would swiggy you know store data onto the computer the very first thing

5:56 is Sugi has millions and millions of customers onto their platform so every

6:01 day there are a lot of transactions which are happening so uh

6:04 this will be happening in two counts of trillions so to store this particular

6:10 trillions of data we cannot store it into a hard form

6:13 or into a particular file or into let's say even an Excel file Excel also

6:17 has limitation so forth uh to store such a huge amount of data

6:22 that too on a day-to-day basis we require to store the data onto

6:26 the computer the number two part you can see is security issues now

6:30 uh you know sweetie gives us the feature to store the card details

6:35 so that we can use it uh next time when we are doing

6:39 this kind of transaction so now the card details or the ATM pin is

6:43 a very important information from a security perspective and that also accounts

6:48 to the trust which is being built by the company so nobody no company

6:53 wants to lose this particular trust Factor so that is why uh database

6:58 or storing data onto the computer gives us a lot more security as compared

7:03 to storing data on to the you know simple file or local file

7:07 into a system now the third point is which is the main point

7:12 and Y is such kind of hole such as data analyst business analysts

7:17 are into picture or a lot more is because nowadays companies are taking

7:22 uh their decisions bases on the data which they are getting so data

7:28 helps us to build much more better decision making so that is why

7:32 it is very much important to store such huge amount of data onto

7:36 the computers and the Very fourth information

7:39 is is information is very readily available

7:42 so let's say I just want to know uh let's say into my particular

7:46 city which was the date always the highest sales have been offered

7:51 so it's just a simple query of it that information is just

7:54 a simple query of it now just think of that if this information was

7:59 saved you know if you know just simple files or uh into the Excel

8:04 file onto the local system this would be a very tedious task

8:07 with the help of storing data onto the computers and with the help

8:11 of SQL every information is just a simple query away so this this is

8:17 how and this is why we are storing data onto the computer

8:20 and uh this is very much useful to us let's move to the next

8:25 section and which is Introduction to dbms dbms is also known as database

8:31 management system now what actually is tpmsr will make you understand in very

8:35 simple terms so for the definition the software which is used to manage

8:40 the database is called database management

8:43 system it provides us with an interface

8:45 or a tool to perform various operations so from the diagram itself you

8:50 can see it is white or very clear that dbms is just happening

8:55 as a kind of a bridge between the user the user can be

8:59 anything let's say a website or an API or a novel person like

9:03 me and you so we'll be querying our uh whatever results which we

9:07 want through the database so dbms acts as a kind of a bridge

9:13 between the database as well as the person who is running the query

9:17 so friends this is all about the database management system from the emails

9:22 only it is very much clear it is acting as a kind

9:25 of an interface between the data wave and the user and the information is

9:30 being retrieved from the database that that happens

9:33 with the help of our database

9:35 management system in very simple words if I have to make you

9:38 understand let's move to the next section here now what can dbms do

9:43 so I have just noted out four of the main important points that TBN

9:48 can do it can do a lot more things uh much more than

9:52 that but into for this particular course these are the four things which

9:55 are very much important to know now the very first part is creating

9:59 the database the second part is

10:02 manipulating the database so creating the database

10:05 so let's say I have to store a particular information about the telephone

10:10 information so I will be creating the database with the help of the database

10:15 management system which is available so it will help me to create

10:19 the database manipulating the database let's

10:22 say a certain person phone number has

10:24 been changed so this process can be also be done with the help

10:28 of the database I can just update the information into the database which

10:33 I have created earlier storing and retrieving data from the database as I

10:39 have explained this earlier from the example of swiggy that if let's say

10:43 if I want to know which is the date on which the highest

10:47 sales have been occurred into into the semi CD so it's just every

10:51 information is just a simple query away so we could retrieve the data

10:55 from the database with the help of the database management system and also

11:00 let's say a user is no more longer or let's say the go

11:04 who stores our information about a certain scheme which is running uh which

11:10 is active and the person let's say he has died so we want

11:13 to remove the information from our database so we can delete the information

11:17 such information which are no longer required from our database so friends

11:21 these all functions can be done

11:24 by the database management system now one important

11:28 thing is database Management Systems one on certain rules and can limit what

11:33 data the end user sees and provide multiple views of the same database

11:37 depending upon the user accessibility so it is very much random in nature

11:41 and they have their own rules assigned and they run on their own

11:46 rules so that is the thing for example you can provide access to write

11:50 on the database to some particular user so let's say uh the uh

11:55 the card details which are being saved onto the platform different platform

11:59 we don't want to give such kind of sensitive information to everybody

12:04 on in this particular world so we just want to give this particular information

12:07 to few people now this particular database

12:10 management system gives us the access so

12:13 everybody every user will be assigned a certain you know username or a password

12:17 which they'll be entering and then they can do all these things

12:20 so database Management Systems helps us into the security purpose also we can

12:25 just grant or we can just give the access to anybody in this particular

12:30 organization whomever I want to give the access or I can revoke it

12:35 anytime if I am having the admin access so these kind of features

12:38 are also available onto the database management system you can just think of how

12:43 important it is from a security purpose now the examples of the database

12:49 Management systems are MySQL Oracle SQL live ports for a SQL Mario

12:55 TV so these are certain examples of the database management system as you

13:00 can see now the query which is running on a MySQL need not

13:05 necessary that the query will run on SQL light or let's say poor

13:10 space SQL every database management system

13:13 has their own different rules attached

13:16 to them so you will have to follow the rules which are given

13:19 by the database management system the rules can be in form of the syntax

13:23 or let's say the function so if I could just simply remember there

13:28 are two different functions swing Aggregate

13:30 and list aggregate Now list aggregate Works

13:33 in MySQL but won't work in SQL server and similarly string aggregator works

13:39 and SQL Server won't work in MySQL so this is the kind

13:42 of difference which I I was talking about we will have to a little

13:46 bit manipulation every now and then when you are running the same

13:49 kind of query same kind of logic into different database management system all

13:54 these varies according to different ppms now let's move to the next section

13:59 there's been a lot of theory for you guys but please bear with me

14:03 till here we'll be solving a lot of different problems we'll be seeing

14:07 the actual the things which you are speaking will be uh you know

14:11 seeing this practically with the help of the queries whatever I have told

14:14 so please bear with me uh stay till the theory part and then we

14:19 will be solving real life problems

14:21 real life database problems and understanding all

14:24 these different things onto our SQL Server management Studio so friends this was

14:29 the thing I was talking about the uh crud operation database as I

14:34 just told you could create the database you can manipulate the data you

14:38 can retrieve the data you can delete the data all this happens

14:42 with the help of the current operations which you can see onto your screen

14:45 C stands for create r stand for read U stands for update and d

14:51 stand for delete so crud is made up of these four things so

14:56 you can just create a database you can read from the database

14:59 you can update the database any any time let's say I have updated

15:04 my phone number so I can update through this update command which you

15:07 can see onto your screen I will just do all of these things practically

15:11 so just bear with me with this theory part you can just uh

15:14 if you are forgetting anything or you are having doubt you can just

15:19 rewind back and then just play the same section again and then come

15:23 back to this particular section this is the best goes on to the internet

15:26 the entire course which is required to get you a job I

15:31 can say that if you complete this particular course you'll be definitely able

15:35 to get that particular confidence that you're ready for the interview so let

15:40 us get back to the video so d stands for delete so if you

15:44 want to delete any information which is no longer required and that is

15:48 catching up the space onto the database

15:50 you just delete that particular information

15:52 so all these are done through the current operation let's move to the next

15:56 section so friends uh types of database so there are two different

16:01 types of database relational and the second one is non-relational so what do

16:06 we mean by relational from the English world what does relation means so

16:11 relation basically means that two or more than one thing is connected

16:15 in some or the other way the same definition is applied here in SQL

16:20 so let's say there are two different tables table a and table B

16:24 now they are connected to each other in some or the other way

16:29 so therefore they are related to each other so to be a relational

16:35 database data should be stored in one or more tables that is definitely

16:40 clear the second thing is each table has rows and columns and the third

16:45 thing is each row is identified by a unique key now I

16:50 will come to this particular unique later but if I just want

16:54 to make your understanding into simple terms uh into our class let's say two

17:00 people had the same name but they had something to distinguish them

17:04 and what was that thing that was the roll number correct so this particular

17:09 roll number is a kind of a unique thing which is attached

17:12 to every person into the classroom no two person can have the same problem

17:19 two person can have the same name two person can have the same

17:22 address let's say there are two person they have the same name they

17:25 also have the same address but their roll number will be a kind

17:28 of a distinct thing which is attached to them and they will be

17:32 recognized by their roll number so that is a unique thing so I

17:35 hope into very simple terms we'll be seeing this is definitely into very

17:39 simple terms the number three point is quite clear now each table will

17:44 have a rows and columns this is also pretty much Clear before moving forward

17:48 to the nosql or the non-relational uh database let us see some examples

17:54 of the relational database so into my next screen you can see here

17:58 I have just copied my previous example which I have taken uh there

18:03 are two different tables you can see table one and table two you

18:06 can just take it them uh into the table one we have

18:10 into the column on the player IDs the ones which have been scored

18:14 by them the wickets that have been taken by them and the catches

18:17 number of catches they have taken a little the second table into the very

18:22 first column I have the player ID and into the second column I

18:27 have the player name so let's say I want to get into the very

18:33 first table into the second column I want to get the player name

18:38 along with the player ID so these two tables there is a join

18:43 condition into the SQL where we can join multiple tables into many ways

18:49 and then we can present the information so let's see if I want

18:52 to get the information of the player name also in addition to the player

18:57 ID so here into this particular example we will have to join

19:02 both of these tables now why are these stable relational it is pretty

19:06 much Clear by now because they are connected to each other how are

19:09 they connected they are connected to a particular column and which is

19:13 that column the column is the player ID column P1 P2 P3 you can

19:17 see in both the tables we have two different columns and they have

19:22 the same information kind of same information so they are interconnected to each

19:27 other with the help of the player ID so this is a kind

19:30 of a relational database let's move to the nosql database nosql database is

19:35 also a pretty interesting thing uh present here so what is a non-relational

19:41 database so in simple words it is not just SQL or no

19:46 not SQL so the name itself which is pretty much clear it says

19:50 not just SQL so definitely means that it has some SQL properties attached

19:55 to it in addition to that there are various other property which are

19:59 present here so friends I'll just explain this into very simple term so

20:05 the data which we get into the real world into the real world

20:08 scenario we cannot be confident that the data will be uh relational data it

20:15 can come in any form and it can be as complex as we

20:20 cannot think also that is why

20:21 this particular non-relational uh came into picture

20:25 and I'll just show you examples of some non-relational uh database or data

20:31 how does it look so there are various examples you can see here

20:35 key value store which is a Json format it can be stored

20:39 in documents it can be stored in the graphs so Theta is stored

20:44 in a kind of a traditional table I'll just explain you with the help

20:48 of simple like samples which I have present here uh don't worry I

20:52 will be attaching this particular PDF

20:54 into the description box of this particular

20:57 video you can just download that particular PDF and then just follow along

21:01 with me into this particular video so friends just you can see onto

21:05 your screen these are some of the example of the non-relational uh database

21:10 how the data is being stored three different images gives three different kind

21:14 of examples the very first example is on to the right hand side

21:18 you can see this customer document if uh I'll have to zoom

21:22 this a bit so you can see I have all the customer details here which

21:32 is present a detail about a customer so I am the customer uh

21:38 you know this is now the key value pair so the key here

21:42 is the customer and whatever comes after the equal to sign this kind

21:47 of forming of value for this particular

21:50 key similarly not exactly this particular

21:53 equal to sign you can see here this address is also a kind

21:56 of key all these things inside this would look curly bracket forms

22:01 a kind of a value similarly Hobbies is a key football and Hiking

22:05 forms a value pair for this particular Hobbies you will not go deep

22:10 into that that is not required for this particular course but I just

22:13 gave the information uh for just a general perspective so you can see

22:18 the customer is the key and all these information about the customers such

22:22 as the ID first name last name age their address Hobbies phone numbers

22:27 all these are the information about the customers similarly and you can see

22:34 this particular graph kind of uh information which is present how a friend

22:39 is related how a person is related to a different person so you

22:45 know this is the kind of formation about the friend Circle so uh we

22:50 need not to go deep into this and the other one is

22:54 a kind of tree based information so we'll just quickly go back and we'll

22:59 move to the next section and let us start with the relational database

23:05 which is the sequel and this course is all about the SQL form

23:09 0 level to advanced level whichever is required for the interviews so relational

23:15 database Management Systems helps user to create

23:18 relational database so we with the help

23:21 of rdba Ms create relational databases they are connected to each other

23:28 in some or the other way we try to store information in the best

23:32 way in which we can and SQL is a kind of a language

23:37 which we use to interact with the database so interacting the database how

23:43 to interact with the database we interact with the database with the help

23:46 of a query now what is a query so let's say anything which

23:51 you put onto the Google search that is also kind of a query

23:55 in itself so you're asking Google for a certain answer you're just posting

24:00 your questions so we need to write a simple query so that we

24:04 can tell our database we can communicate with our database we can interact

24:08 with our database to provide us the relevant information so SQL is

24:12 that particular mode of communication to help

24:15 us to retrieve information from the databases

24:19 so SQL is a kind of a form of communication language similarly to all

24:26 these languages English in the we communicate with each other with the help

24:29 of this particular language SQL is a language which com which we

24:34 utilize to communicate with the database so I hope the definition of SQL

24:40 is quite clear we'll be seeing into a lot more detail what SQL

24:43 can actually do how do we use the queries to solve the different

24:47 problems into SQL so let's move to the next section the SQL query

24:52 which runs on one rdb and this need not necessarily run on the other

24:57 one too so this I discussed a query which is running on MySQL

25:01 it will there's no guarantee that it will run on postgres SQL

25:06 also you will have to do certain modifications there will be no modification

25:10 in terms of the logic there will be modifications in terms of this syntax

25:14 because there are two different there are two different kind of database

25:19 management system and under the current operations I have given into a lot

25:23 of more detail I don't want to go into t let us move

25:26 to the next section now why SQL why do we utilize SQL very

25:31 first thing is very much clear that there should be a certain language

25:34 through which we can communicate with our database but also there are many

25:40 things which comes in addition to that the first thing is the faster

25:44 processing speed the second thing is the minimal requirement of coding so if

25:49 you will just see as a new B SQL code would look like

25:52 some English language a person has simply written into a kind of query

25:59 and then he's getting the data it says there are very minimal knowledge

26:03 of coding which is required to learn SQL or perform SQL to generate certain

26:09 results the third thing is the easier data manipulation you can just use

26:13 SQL very easily to get the data and make decisions based on the data

26:19 which you are getting before which is pretty much the very important thing

26:22 is the security issues which are provided by the SQL so nobody can

26:27 access anything any data which is available only certain people whom we want

26:32 to give the access to the data they can only access that particular

26:35 data so this is the kind of very important thing which is required

26:40 nowadays because many applications they are

26:42 saving your car details this information should

26:45 not go out into public this will create a very huge impact

26:49 on the touch tissues because your data is getting leaked so all these things

26:53 are handled by SQL very nicely let's move to the next section uh

26:58 and which is the data type now friends is meant by a data

27:03 type if I would just go to my very first screen where I

27:07 just gave you an example of what was database I'll help you make

27:11 you understand there don't worry we'll be applying all of these things

27:15 practically but before applying things practically

27:18 you need to understand what does all

27:20 of these things they mean and how is these things related to the real

27:25 world then only it will be helpful when you are doing it practically

27:29 don't worry I would I'm trying to do this story party to very

27:33 concise uh as much as I can let us see about what are

27:38 the data types now friends from this particular

27:41 information you can see the telephone

27:44 directory uh table for now so you can see into the column one

27:49 we have person so how the person IDs are getting uh shown here

27:54 so it's kind of P1 P2 P3 now into the next column we

27:59 have the country code into the third column we have the state code

28:02 into the fourth column we have the number of that particular person so friends

28:07 uh what is meant by data line into very simple terms it is

28:13 a way of storing different kind of data which is coming so data

28:18 can come in the form of numbers you can see into the second

28:21 third and fourth column the the data which is present is in the kind

28:26 of numbers our data can come into simple text form let's say there's

28:31 a column which is the name column student name column so into that particular

28:36 column we'll be having data stored in the form of simple names

28:40 so let's say simple names such as such as you can see onto

28:44 this screen into the column B here all these different names which

28:48 are present are simple text so we cannot assign the same data type

28:53 to a column which contains which will be containing the number values

28:58 or and the column which is also having the string values so definitely the data

29:04 type should be different for both the different columns so that is how

29:09 the data will be stored this is a very simple example which I

29:12 gave here on what is exactly meant by data type also that is

29:16 let us assume this is a column which contains the date let's say

29:20 the transactions are happening and we need to store the time sample let's

29:24 say time on which the transaction has

29:26 happened and date on which the transactions have happened we need to store

29:30 this particular information into a particular column

29:32 so friends what will be data type the data type for that particular

29:37 column cannot be the same as the data type for this particular name

29:41 column or the data type or you know the integer column the data

29:45 type of the number column so it has to be different and what

29:50 different it is so I have provided examples here into this particular sheet

29:56 or the data types which are available right now into the SQL server

30:01 and be in form of strings let's say the name which we are

30:05 storing so the very first example which will be seeing here is

30:08 of the string data type again we'll be seeing this in a lot more

30:13 detail into when we'll be creating our database and we'll be running

30:18 our query practically so this is just a simple uh brief which I am

30:23 giving right now so that when we move on you don't face any

30:26 issues you don't face any problem so the string data type are there

30:30 are many different kind of string data type worker worker so these are

30:37 different kind of string data types which are present here text only common

30:41 thing which is there to all of this different string data types are

30:46 is that they store string kind of values or let's say the name

30:50 values which have a string attached to them but when you'll be

30:55 moving deep into all of these different data types they are different world

30:59 in themselves so if people just see the character the description says fixed

31:05 with character string the maximum size which

31:09 this particular character and you can store

31:11 is 8 000 characters and the storage is the definite width similarly

31:16 in this worker that the descriptions is

31:19 variable with character string and the maximum

31:23 size is 8000 characters and storage is two bytes now what is the simple

31:27 difference between the care and the wire kind of so I will just

31:31 simply explain you let's say there is a particular column and we

31:37 have given the data type of that particular column as character uh n

31:43 and where Karen and where n is let's say 500 so I'll just

31:48 simply explain you the help of a simple Excel sheet and which you're seeing

31:52 here is a kind of integer value which will have to provide so

32:00 let's say there's a column which is of data type wire care 500

32:10 there is another column which is of the data type worker care 500

32:15 sorry now and if I'm storing the same information here let's say I'm

32:23 storing information of my name itself so what will be the difference between

32:33 this particular data types the data which will be stored so in care

32:39 as you can see from the definition it can the maximum size

32:43 of character which we can give here is 8 000 characters now the number

32:47 of characters which are presented to my name is is which you can

32:52 just see here using the length function so that is the eight so

33:00 8 is definitely less than 8 000 so into both of these cases

33:05 uh this will be called as OK because the maximum size which we they

33:10 can have is 8 000 characters so this is pretty much fine

33:13 now into the care you can see the description it is written fixed

33:17 with character string and into the uh where it is written variable width

33:23 character string so even if into this particular curve even if my name is

33:30 of eight characters but in care it will occupy 500 character link because

33:37 the the data type which we have assigned here is scare 500 so

33:42 in care it whatever you enter it will take the same space which

33:47 you have given into the data type for this particular column so we

33:52 have given here the data type as scar 500 so even if

33:56 my name is of eight characters when it is being stored in the care

34:01 column data type it will occupy 500 characters with while in comparison

34:07 to worker it will only occupy as much as it is so it is

34:12 of eight characters it will only occupy eight character weight even if

34:16 the maximum which we have given is 500 so you can just assume it

34:21 the maximum length of uh value which we can store here is a 500

34:26 length and otherwise it will occupy the same length as the character it

34:31 is let's say my name is here of 8 characters so into the backer

34:36 column it will occupy only eight uh characters with while in care

34:40 it does not happen it will occupy whatever we have given it says

34:45 of 500 width it will occupy 500 with character length so this is

34:50 how can work internally it works and this is the basic difference between

34:55 care and work and everything here I would request you to go through

34:59 this particular sheet and this will help you to understand how this particular

35:04 data types even if there of this string data type they are quite

35:08 different from each other so you will be getting an idea of about

35:13 how are they different so these are the some of the nitty

35:16 gritties which are present into each of these string data types similarly

35:20 into the next sheet you can see there is a numeric data type friends

35:24 into the numeric data types also there will be various different cases which

35:29 we will we will be tackling let's say let us assume that the marks

35:36 which we are getting let's say in 50 will be having certain marks

35:39 some people will get 40 marks some will get 35 marks some may also

35:44 get 37.5 marks so to store this particular decimal values into our database

35:51 that data type of that particular column will be different from the integer

35:56 so from the integer is very much clearer there that won't have any

35:59 decimal point one two three four five six seven eight nine ten similar

36:03 kind of numbers are integer values but when it comes to the decimal

36:07 point value such as 37.5 the marks can be given as 37.5 definitely

36:13 so we will need to store such kind of values into a database

36:18 just so to store such kind of value such step decimal values which

36:22 are of numeric data type we will be having to use a different

36:26 kind of data type and which is you know a numeric you can

36:30 see a numeric P commas or a decimal P commas these are used

36:35 to store decimal points if we need to store our integer value we'll

36:40 be using the int data type which is present here let's say we

36:45 are showing a very huge integer phone directory example which I gave you

36:50 earlier you could just assume our phone numbers are of 10 digits so

36:55 to store such large number of digits we will have to use a different

37:00 data type and what it is it is of big end all

37:03 of these rules all of these different cases I mean how I am tackling

37:07 this all have been written here into this particular sheet this particular PDF

37:11 is available into the download section don't worry I'll be attaching this here

37:15 you will download it from here from your future reference this document is

37:18 Enough For Preparing your you for your interviews you can just go through

37:23 this day before your interviews you can just brush up your skills

37:28 or brush up your knowledge from here so this is all about the numeric

37:32 data type we'll be seeing this into a lot of more detail when

37:35 we'll be solving our problems and to our SQL Server so let us

37:38 move to the next screen print date type so similarly numeric and the string

37:43 data type there is another data type which is the time mandate

37:47 data type so let's say there will be a column in which I'll

37:51 be just storing the time I don't want to store the date there

37:55 is a column in which I want to store the date I don't

37:58 want to store the time I'm just concerned with the date thing and there

38:02 will be another scenario where I'll be stored I want to store

38:06 the timestamp I want to store the date along with the time in which

38:10 that particular event has been happened let's say I got my Sugi order

38:15 I want to have all these three information in column A I'll have

38:20 the date on which I ordered that to your product into the column

38:23 B I'll be having the information on the time on which the order

38:27 is delivered to me I'll do the third column I'll have the information

38:31 of the date and both the time on which my order has occurred

38:37 so I I would just make you understand so let's say there

38:40 will be a order ID into the next column it will be date

38:45 on which the purchase was made the time on which the order has

38:49 arrived and into this particular column it will contain both so date time so

38:56 I have you can just assume this kind of data type also so

39:00 let's say the order for order ideas one the date on which the order

39:06 has arrived I'm just writing it down and the time you know let's

39:11 say it is 6 pm [Music] we'll destroy this year 6 pm 16.

39:25 uh and I can just change this to 18.

39:30 okay yeah so this is the 6 PM obviously

39:33 uh delivery has arrived and into this particular column

39:38 I want to have both the information the date

39:41 on which the delivery happened as well as the time

39:45 on which the delivery is received so you

39:50 can see here I can store information in any

39:53 way which I want so all this is possible

39:56 because of the different data types which is available

39:58 into the SQL and all this information you can

40:02 see are present onto this particular PDF you can

40:05 just go through this PDF which exactly data type

40:08 I should use for my case when I'm building

40:11 a particular column what type of information I am

40:14 saving you can use your reasoning skills or you

40:17 can just rewind back I gave multiple examples when

40:20 I'm when I was trying to explain you so you

40:23 just rewind back go back analyze what kind

40:25 of problem you're solving what type of information you're storing

40:29 into that particular column and utilize the best data

40:32 type which is required for that particular column so

40:36 friends this was all about the data types which

40:39 are present into the SQL I hope you'll go

40:42 through all of these different shapes that is very

40:45 important for you because in two interviews uh the interviews

40:49 they are pretty much to ask about all

40:51 of these different data types which are present let us

40:54 move to the next section and let us begin

40:57 the real magic of the sequel now from here

41:00 we'll be solving the problems so let us install

41:04 ssms now what is ssms ssms is SQL Server

41:09 management studio now the why did I choose SQL

41:13 Server management Studio first of all it is one

41:16 of the best tools for SQL which is

41:18 a label onto the internet so and the installation process

41:23 is very very simple you don't need to install

41:26 many other things it's just into the two links

41:30 which you can see onto your screen you just need to go to both of these links

41:34 and install your SQL Server I would help you

41:37 here I'll just I'll be providing this particular document onto

41:42 the description box and you can just go

41:45 to both of these links which are present here

41:48 and what you need to do is first of all

41:53 we'll be seeing this particular interface and we'll be

41:56 opening the very first link you need to go

41:59 here and you need to download this free download

42:03 for SQL Server management studio ssms 19.0.2 so you

42:08 just download this particular file in the second file which

42:12 you need to download is of this particular

42:14 second link which I had pasted there you need

42:17 to scroll down and there'll be two different versions

42:21 which will be available it will be the developer version

42:24 and the other one will be Express version you

42:27 can download anyone but here I'll be using the express

42:30 version so you can just simply hit the download

42:32 now button and the express version will be starting

42:36 to download similarly for here SQL Server management studio

42:40 will start to download now after you've downloaded both

42:43 the files I have both the files ready here as you can see onto my screen uh so

42:49 one of the file is of the huge uh you know 669 1000 KB and the other file

42:57 is of 6000 KV so first of all you

43:00 will need to install the file which is of higher

43:04 size so you just double click onto this particular

43:07 uh ssms setup enu and you will be

43:12 getting uh this particular interface so for me it

43:16 is installed from before I would not do it

43:18 again but the steps are quite simple you just

43:22 have to hit next next next and the SQL

43:25 Server will be installed after installing this SQL servers

43:29 software you will be getting this interface uh so

43:34 for me it was installed from before so

43:36 that is that is why it is showing as uninstalled

43:38 so I would not unsolve it for now

43:40 but you'll be getting a success message that the server

43:44 has been installed if you're facing any issues you

43:48 will just write down into the comment box after

43:50 you have downloaded the SQL Server management Studio or installed

43:54 it you just write onto your search bar ssms and just do it for a few seconds so

44:00 you'll be getting this particular interface here you will

44:03 need not to do anything you might face a little

44:05 bit issue here but I'll just solve this out

44:08 for you so here you'll be confused on what

44:11 do we write onto this server name so if

44:14 you were just quickly see here my server name

44:18 is something random and then slash SQL experts now

44:23 what is that random so that is my username

44:26 basically so you can just see if the username

44:28 thing here and it is the thing before

44:32 the slash it exactly matches at both the sections so

44:38 you just have to copy this particular thing which

44:41 is present into the your username before this slash

44:44 paste it here we will slash like SQL Express

44:48 and that will be your server name so this is

44:52 these a small issue which you might encounter I

44:55 don't think apart from this anything else you would

44:58 be uh encountering let us simply connect it here

45:02 and we are ready to run our queries our main

45:06 payloads let us move to the next section I

45:10 will just call this out again if you're facing

45:12 any issues in installing ssms you can just write

45:15 it down into the comment box of this particular

45:17 video let us move to the next section

45:20 and the thing which we are waiting for is ready

45:23 we'll be starting with the credit operations we'll just

45:26 see how query SQL query Works how everything works

45:30 so uh basically current operation there are four different

45:34 things number one is ddl DML DCL DCL we'll

45:39 be seeing all of these four different things

45:41 into lot of more detail first of all let us

45:44 start with a very important one which is

45:46 the TDL what does ddl mean ddl means data definition

45:50 language so into the data definition language there are

45:55 two or three things number one thing is creating

45:59 new database or table number second is the alter

46:03 so if you want to change anything let's say

46:06 if I want to add a new column to our the newly created table so we can alter

46:12 the structure of the database the third thing

46:15 is the drop deleting uh you know deleting objects

46:19 from the database permanently and the number four thing is

46:23 from gate so removing all the calls from the table

46:26 and not the table so the drop in the truncate

46:29 this is a very famous SQL interview question

46:31 what is the difference between the drop function

46:34 and the transit function the drop basically deletes the entire database

46:39 or the entire table you will not keep

46:41 the table also while in truncate it will not delete

46:45 the particular table it will just delete the data

46:49 which is present into that particular table so all

46:51 the records it will be vanished all the records

46:55 it will be deleted not the table this is

46:58 the very basic difference between the drop and the truncate

47:01 command let us move forward to our SQL

47:04 Server management Studio which we have installed few seconds

47:08 back and will hit on to this new queries

47:13 section and we'll start pairing or creating our database

47:18 or the table from here now on so first

47:21 of all what do we need to create first of all we will be creating our database

47:27 and into our database we'll be storing multiple tables so

47:32 this will be our flow so first of all let

47:34 us create our database now and we'll be storing

47:37 the information about students of a particular tool so

47:42 it will create a database and the database name

47:46 would be student so I'll just try to create

47:50 database to test and again this is the column

47:56 the command is very simple it is create database

47:59 students so we are just telling to create

48:01 a database and inside that particular database will be stored

48:04 in multiple tables so I'll just select the entire

48:07 query here and I'll just execute it here you

48:10 can see commands completed successfully but wait for a minute

48:14 I cannot see database onto my screen where

48:17 the database has been created so to see where

48:20 your database has been created you need to go

48:23 to this particular section here it on this particular

48:26 plus icon here you will see this database again hit

48:31 onto three this plus so you can see

48:33 there was a database which was created earlier such

48:36 as tutorial which is Created from before now I

48:40 created this students database and you can see here

48:43 this particular students database is ready now into this particular

48:48 database is there a table present from before

48:51 so there are certain tables right now I haven't

48:55 created anything so there's nothing which has been present here

48:59 now later on we'll be creating tables multiple tables

49:03 about the student details which will be storing here

49:06 so this is how we have created our database

49:10 now the second thing is let's say you can

49:14 see from this particular example uh I have two

49:18 different database into my particular system right now one

49:21 is tutorial one is students definitely I whatever uh

49:26 things which I'm doing later on let's say I'm closing

49:30 this particular session for now later on I come

49:34 back and I'll be using my SQL Server management

49:38 studio and I want to let's say make

49:40 a new table inside a new database which I have

49:43 created and the new database was of the students

49:46 so how do I do that so I'll just connect it here I'll move back to the new

49:52 query into the database you can see students have been

49:58 created now there are two different database which

50:01 is present here right now when I'll start writing

50:04 with query I would not know when and where

50:08 is the data whatever functions which I'm writing where it

50:11 is happening so I'll have to tell my port

50:14 that use this particular database whenever I'm writing something

50:18 and utilize that particular database store information into that whatever

50:22 the next informations which I'll be writing so I'll

50:25 be making a new table into the students database

50:28 so I just write here use two pins that's

50:35 all that's always required I'll execute this and from now

50:39 on whatever things I'll be doing that will

50:42 be stored into the database students so this is

50:46 what is the example thing which I was talking

50:49 about is if there are multiple database into your system

50:52 we'll have to tell our code key use

50:54 this particular database for the next functions which I'll

50:57 be doing so that we have done friends we'll

51:00 be creating a very basic a very simple table

51:02 here into our students database so will create a very

51:08 simple named as details and here we'll be

51:15 storing very simple information which is about the students

51:20 the roll number their name uh their address

51:24 and their marks their subjects so different kind of information which

51:30 we'll be storing here boom create a table we'll

51:32 write here create table details so the table name

51:36 is details we have told uh the SQL Server

51:39 that we need to create a table in the table

51:41 image details now we need to open a bracket

51:46 close it so what is the information which

51:50 will be writing here here we need to mention

51:52 all the different columns which we want to store

51:55 into our table which will be created so

51:59 let's say I want to store the roll number

52:01 of the students and I want to store the the subjects

52:07 of that particular student into the next thing I

52:13 want to store the marks of that would be

52:20 a student and into the next I want to store

52:24 the address of that particular student now I have

52:31 let's say right now I'll be storing these four

52:34 columns into my particular table so as I discussed

52:39 earlier for every column which we are writing or creating

52:43 into our database we need to provide the data

52:45 type of what kind of data will the user

52:48 be storing into that particular problem so the roll

52:52 number column will have numbers values such as one

52:55 two three four five six seven eight hundred kind

52:58 of values so it will be integer data type

53:02 column the subject name will be from the name

53:07 itself it is very much clear that it is a name column and we will store the name

53:11 of the subject such as science maths social science

53:14 so it will definitely be a string data type

53:18 column so it will definitely be I can just

53:22 store a work or and I'll just give a limit

53:26 of 200a similarly marks Mark says of the integer

53:32 data type because people can get marks that is

53:37 40 50 60 Auto contact let's see the full

53:40 marks is 100 I'll just mention a column also of full marks and uh here also it

53:49 will be integer let's say the full marks is

53:52 of 100 we'll just write this down don't worry

53:55 um and the marks which have been scored out

53:57 of 100 now wait a minute as I discussed

54:00 the marks can be of the decimal data type

54:03 value also so we'll have to store a decimal

54:06 data type here so I'll just write here decimal

54:13 and the number of places before the decimal places

54:16 which we want so let us say I want

54:19 10 decimal places before the decimal point and number

54:23 of places after the decimal point so let's say

54:25 I want to I'll just write here 10 comma 2.

54:29 the address ID so this can be a name

54:32 or this can be your integer value for now let

54:36 us give this as a wire cap data type

54:39 so I'll just write here where I can comma 200.

54:42 so all these information is enough to create

54:46 a table now later on we'll be seeing what

54:49 all other informations which we can give here

54:51 which we can supply here but this one is the basic Syntax for creating a table

54:59 into the database students so I'll just select this particular

55:05 code I'll just execute this and you can see

55:08 it is telling commands completed successfully now where is

55:12 this table created it is created in students

55:15 database as I just mentioned you earlier now if

55:19 you remember there was no tables which was present

55:21 earlier now I will go to the students database

55:24 tables and I'll just sit on this you can see here dvo Point details have come up

55:37 so new table have been created which is named

55:40 as details and you can see all these columns

55:45 which I had written are now stored and you can see all of these things and what

55:51 is the kind of the data type every

55:54 information is present here you can see here null

55:58 information which is coming out as null uh everywhere

56:03 so we'll come to this which is a very important thing into the SQL when you are

56:08 creating a table now the table has been created

56:12 now you will tell me after those the table has been created now how can I insert

56:17 information into this or how I can query

56:19 this particular table now the very simple thing is

56:23 how do we query a particular table so we query it like selling star from and we

56:30 need to write the table name that's all that's

56:34 all how we want to see the entire details of a particular table so we'll just do

56:40 a select star so it's telling star means everything

56:43 so we're just telling just show me everything

56:46 from the table which is named as details so I'll

56:49 just execute this particular query so you can

56:52 see the column names have come up with all

56:54 numbers subject name Marks full marks address ID

56:56 but we haven't inserted any information yet so that is

57:01 why you cannot see any information so let

57:03 us do the next thing which is inserting information

57:05 into this particular table so I'll just write

57:09 here into detail so the table name is detailed

57:16 so we'll have to mention here insert into details

57:19 and here we need to mention all the column

57:22 names in which we want to insert the data so I'll just write here all the column

57:28 names present into the details table so after

57:38 we have written all the column names we want

57:40 to insert details so I'll just write here

57:43 values and after this I'll just insert you know

57:48 five details five row details first all the details

57:54 I'll be writing into this particular bracket so

57:56 let us say the roll number is one

57:59 the subject is maths are the maps which have been

58:06 received is let's say 50 the full marks was 100 address IDs let's say A1 so we

58:19 have stored this particular information we'll just copy

58:21 this we'll paste this into all of these brackets

58:25 and we'll change the information wherever it will be

58:29 necessary so the roll number is 2 the object

58:36 is let's say science the full marks is

58:40 the marks which have been scored is let's say 80.

58:45 and the box is 100 this will not change that this is A2 similarly

58:51 I'll change into all of these different rows I've entered all these information

58:56 I'll just execute this particular command and you can see it is showing

59:02 message as five rows affected that means that five rows data have been

59:07 inserted into our table which is the details now earlier if you remember

59:11 I was running the same command which is this let's start from details it

59:15 wasn't showing any information right now let's execute this let us see okay

59:19 the information is now stored and you can see all this information have been

59:24 coming up you have given this particular data type as this one but you

59:29 haven't stored any decimal number how do I know that this works so

59:33 let us insert a decimal uh number or information here so at least

59:39 write here 14.55 okay let us execute this particular command and select us now

59:53 see model details are present yes I'll just execute selection from details

59:57 and you can see here it is the last column I am getting information

1:00:01 of 40.55 so this particular decimal thing into Works in this particular way so

1:00:07 you are getting two decimal places after a decimal point so number of digits

1:00:14 which are coming after the decimal points is two so this particular 2

1:00:18 means that particular thing so uh this is how the flow data type

1:00:22 of the decimal data type it works so friends we have seen the insert

1:00:27 command let us next see the other command which is the alter table

1:00:32 now in in addition to all these informations which are present here let

1:00:37 us say I want to add a new column and that column would include

1:00:41 the parents phone number of all of these students so let us have

1:00:46 or let us insert that particular information also uh so we need to add

1:00:52 a particular column which is the parents phone number so how to add

1:00:56 that on what is the syntax so table details and I'll write here

1:01:03 add phone number and I left right here the data type and the data

1:01:14 type let's say I'll pick up as begin I'll close this I'll run

1:01:20 this particular command I'll execute this and you can see the command has

1:01:24 been completed successfully let us run this x sharp from details to see if

1:01:29 the phone number column has been added and you can see the phone number

1:01:32 column has been added but all of these are having null records present here

1:01:38 so but the phone number column we have added with the help

1:01:41 of the alter command so alter command

1:01:43 is used generally to change anything which is

1:01:47 currently having is not present into our database so let's say we want

1:01:52 to remove a particular column that also we can do with this particular alter

1:01:56 command so to remove a particular column let's say I want to remove

1:02:00 this full marks column so I'll just write here all along and we need

1:02:05 to write here the column name so the column name is full marks

1:02:08 I'll just select entire query I'll execute this and you can see the commands

1:02:14 have been executed successfully let us see

1:02:16 into the details table whether the full

1:02:18 marks column is present or not so I'll just select the entire query

1:02:22 and you could see that full marks column is gone now so this is

1:02:27 the usage of the alter commands you can do a lot of many

1:02:31 different things you can change the data type of a particular column so

1:02:35 you can do all of these things using the alter command I hope

1:02:38 the order command is quite clear now deleted a column you have removed

1:02:46 a particular column and you have added a new column now how we store

1:02:50 information to the new data uh structure which have been formed into the new

1:02:55 table structure which has been formed let us insert a sample data here

1:02:59 into this particular new table so I'll just copy the same command

1:03:03 from the previous row or let us use the same thing so the roll number

1:03:08 is present subject name is present marks is present the full marks is gone

1:03:13 so I'll remove this because it will throw me uh error that the column

1:03:17 is not found and definitely the column is not there so there's no

1:03:21 meaning inserting data into that particular

1:03:23 column instead a new column which has

1:03:25 come up as of the phone number so I'll just write it here

1:03:29 in addition to that I'll remove this particular full marks Henry which I had

1:03:34 given earlier and in the phone number I'll just write here uh a phone

1:03:41 number so and I would copy this paste it here again I'll utilize

1:03:52 the same phone number into the next entry so some of these are

1:03:57 some of the dummy values which we are entering that's all is required let

1:04:03 us execute this particular query here and you can see it is still

1:04:20 two rows are effective let us select start from details and you can see

1:04:24 we are getting the new entries of the phone number which we have

1:04:27 added and there are no entries limited key for the full marks column

1:04:31 because we have removed that particular column so we have seen the create

1:04:35 command we have seen the insert command we have seen the how do we

1:04:39 create databases uh let us see how to truncate this particular table so truncate

1:04:46 basically means it will remove the entire

1:04:49 information which is present into a particular

1:04:52 table so I'll just show you guys right now I'll just do

1:04:56 a select sort from details and you can see all these informations are present

1:05:01 now for trunk it I'll remove all the data which is present into this particular

1:05:06 table details table just the table design will be present and the entire

1:05:12 data will be vanished off so the command to truncate a particular table

1:05:16 is eight table details I'll just write it here and I would execute

1:05:25 this particular query and you can see the command has been executed successfully

1:05:30 let us run this selection from details do you see any data here I

1:05:35 cannot see any data I just see the table design the table columns

1:05:40 which are present here so it has not deleted any information so even if

1:05:46 we have truncated the table we can insert reinsert the information into it

1:05:51 so I have let's say I'm just running the same command as before you

1:05:56 can see it is saying two rows affected I'll just do a select

1:05:59 star and you can see the two rows have been inserted just by clear

1:06:03 that concave does not delete the table design which is present into the packet

1:06:07 it will just remove the all the information all the data which is

1:06:11 present into the table right now while in comparison to the other command

1:06:16 which is present here which is the draw while this particular drop command it

1:06:21 can delete the database permanently it can also delete the objects or the tables

1:06:25 which is present into the database so this is the use of the drop

1:06:29 command so I'll just quickly show you let us drop this particular details

1:06:34 table which we have created right now so before that I'll just show

1:06:41 you the table is present as we can see it selects shortcom details

1:06:44 table is coming up now instead of strong gate I want to drop so

1:06:49 I'll just select this and execute

1:06:51 this command I've been executed successfully and what

1:06:56 will be the output which we will be getting after doing a select

1:07:02 star from details now that we have dropped this particular table so I'll

1:07:06 execute this and it is telling that uh invalid object name details is

1:07:12 present here so there is no object no table named as details which

1:07:17 is present and if we try to insert the data will it happen no

1:07:21 because the table details have been

1:07:23 completely removed from the database itself so

1:07:27 what do we need to do to insert data into the table details again

1:07:31 the same process we need to create a table so I just created

1:07:36 the table as you can see the table has been created or not so

1:07:40 do a select star table has been created let us insert the data

1:07:45 into the table and it is not happening because the column names I had

1:07:50 changed earlier so to let us do one thing add a column here

1:07:56 as phone number and key base it has built in it now we have

1:08:03 changed the design of the table so first I'll just drop the table

1:08:10 I'll recreate the table 13 let us see if there any information is present

1:08:15 into the table no information is present the table has been created and finally

1:08:22 let us insert the data into the table so you can see two

1:08:25 rows are affected it is showing let's see if the two rows are

1:08:29 inserted or not so you can see the two rows have been inserted

1:08:32 so friends this is all about the day DL data definition language and we

1:08:39 have covered everything so we'll be going like this so we'll be covering

1:08:44 the theory part we'll be understanding that would be help of very simple

1:08:47 example state to date examples I'm trying to make this as possible as Layman

1:08:53 language as much as possible and we will see all of these things

1:08:58 which are present here onto your screen to a lot of more detail now

1:09:04 coming next to DML data manipulation language and into the DML we have

1:09:10 the insert we have the update and we have the delete now friends insert

1:09:16 data into table we have seen this we have inserted data into our table

1:09:21 and we have seen this particular syntax what if and where do we

1:09:26 use this update and delete command now friends let's say for a particular

1:09:31 case a student's phone number have been updated from the previous thing so we

1:09:37 need to update that particular entry so that the phone number gets updated

1:09:44 and in addition to that let's say I want to delete the previous phone

1:09:50 number so friends this particular thing uh this particular commands is used

1:09:56 to update a particular record and also

1:09:58 delete a particular record which is present

1:10:01 from before let's see this into particularly

1:10:05 onto the SQL Server management studio

1:10:07 so I'll just go here uh you can see here I have a table

1:10:15 image details I will be using this particular table only to show you

1:10:18 what does update and delete command to at certain values so I'll just drop

1:10:24 this particular table here and we will create the table again and I'll

1:10:33 be entering two different student information roll

1:10:36 number ID as 1 and roll number

1:10:37 ID is two so I'll do a select star and you can see

1:10:44 I'm having with all number subject name the phone number let's say the phone

1:10:49 number of student ID as 1 has been updated and has been changed

1:10:55 from this it has been changed to say this so I want to update

1:11:09 the entry into my table how do I do this we'll be doing

1:11:12 this with the help of the update come on the syntax of update syntax

1:11:17 of update is something like update and we need to write here the table

1:11:23 name we need to write here set we'll need to write your column

1:11:30 name correct so what do we update the phone numbers whatever is present

1:11:39 before it will be updated to whatever we give within this particular quotes so

1:11:45 right now you can see it is nine zero zero zero zero it

1:11:50 will be updated to nine zero zero four so friends how will our code

1:11:56 recognize how will the update command recognize

1:11:58 that we are talking about the student

1:12:01 who is having the role number as one so we need to specify

1:12:06 this that I am talking about I am talking about changing the phone

1:12:09 number of the student whose roll number is one so we need to provide

1:12:14 this into our code at some or the other place and we need

1:12:18 to provide this as update detail set phone number is equal to whatever

1:12:23 where all is a button one that's all so we're just telling our code

1:12:32 that where a roll number is equal to one update into the details

1:12:38 table and set the phone number as this particular phone number let us

1:12:44 execute this particular code friends so you can see each slim has one row

1:12:48 has been affected let us see if the entry has been updated or not

1:12:52 so I'll just do a select stuff in details and you can see

1:12:56 earlier the phone number was nine zero zero zero zero and it has

1:13:01 been updated to nine zero zero zero four so this is all about

1:13:05 the update command uh let us see let us move to command delete record

1:13:12 into a particular table let us assume that the student ID roll number H2

1:13:17 has uh left this school so the data of the student ID row

1:13:23 number two should not be present here so how do I remove this particular

1:13:27 information from here so we'll be using the delete command as well user

1:13:31 delete here also we'll need to mention which is the exact entry which I

1:13:37 am talking about so I'm talking about the student having roll number as two

1:13:42 so the student has left this school so I'll have to probably get

1:13:45 delete from details where overall is equal to two so you can see

1:13:51 right now the entry forward number 2 is present I'll execute this you can

1:13:56 see one row effect here let us execute the select shot from details

1:14:00 and you can see only one row information is present and the student ID

1:14:05 problem is 2 has been deleted and this is all about the delete

1:14:09 and the update command which is present into the DML which is the data

1:14:13 manipulation language two parts which is the DCL and the TCL so DCL

1:14:19 simply means data control language now many

1:14:22 times into this particular video I have

1:14:24 just told how security plays a important role in today's time so we

1:14:30 can just grant the permissions to see the data or even update the data

1:14:37 insert the data we can grant the information to specific users with the help

1:14:42 of the DCL which is the data control language also if you are

1:14:47 granting the permission we can read all the permission anytime so these are

1:14:51 some of the security benefits which we get with the help of this SQL

1:14:56 so using SQL we can grant the access to people and we can

1:15:00 revoke the access also the last is the transaction control or language so

1:15:09 the number one here is the commit so at whatever step we are we

1:15:13 let's say I just want to do it for now I want to save

1:15:18 it for now we can do it with the help of the commit

1:15:21 function when times what happens is we have saved the information but we

1:15:26 just remember that the last step in which we have done some some

1:15:30 changes or anything uh that is done wrong and we need to go back

1:15:35 to the last step and do the changes accordingly and we need

1:15:39 to save our work so the rollback

1:15:42 command is useful in that particular perspective

1:15:45 that we can just roll back to the the last commit part and then

1:15:49 we can do the changes and then we can save our work now

1:15:53 this another and last in which is the save point now what does

1:15:57 save point do so it identifies a point in the transaction to which

1:16:02 you can go back to later so you can say you can save

1:16:06 whatever functionality you are doing whatever code

1:16:09 you are writing you can just save

1:16:11 that particular part of code at that point of time and then just

1:16:16 rewrite your code and also save it multiple times so that you can just

1:16:21 roll back it later at exactly the point which you want to so

1:16:25 save point is utilized or used into that point so the next section here

1:16:30 let us understand more details onto the SQL the basics of the sequel

1:16:36 so friends you can see onto my screen primary key primary key plays

1:16:41 a very important role into the SQL whatever we were doing till now creating

1:16:46 database creating tables you would not have heard me using the term which is

1:16:52 the primary key I was always using a term which is the roll

1:16:57 number is the unique thing for each of the student the raw number

1:17:00 ID is the unique thing for each of the student now this particular

1:17:04 roll number in general term is the primary key of the data which is

1:17:09 stored into my table so friends you can see onto my screen

1:17:14 that primary key not in simple terms is a primary key in simple term

1:17:20 a primary key is a column which is present into your table in which

1:17:25 in each of the row and a unique information is present for example

1:17:30 into this into the screen you can just see do the leftmost part

1:17:34 of the table the primary key is the roll number column the second column

1:17:40 is the name column and the third column is the stream column now friends

1:17:44 into the roll number column each of the student will have a unique roll

1:17:49 number and through which they are distinguished

1:17:52 as a unique student now two students

1:17:55 can have the same name as you can see it is marked in red

1:17:58 two student name that's Robert they have the same same name you know

1:18:03 so that can be a general case but those two students are two different

1:18:08 students so this should be something unique to distinguish them so the roll

1:18:13 number is the unique thing or the primary key of this particular table

1:18:16 you can see now a very very real life example is your other

1:18:22 number so aadhar card is in information which is recognized in India and every

1:18:29 citizen have been is having given a unique aadhaar card number and that is

1:18:34 unique to every citizen so even if multiple citizens let's say they have

1:18:38 the same name they live into the same state they live they live

1:18:42 into the same city they live into the same area but their unique number

1:18:47 is the aadhaar number through which they are recognized so the primary key

1:18:52 of this particular table the second table you can see is the aadhaar number

1:18:56 the First Column is the other number the second column is the name

1:19:01 of that particular person the third column is the state in which the person

1:19:05 lives so even if the name is same state also is same cities

1:19:09 same the area is same but two people who are having same information

1:19:14 but they are recognized differently using

1:19:17 the aadhaar number so friends this is all

1:19:19 about the primary key I just gave a very simple example to make you

1:19:23 understand about what is a primary key I hope is pretty much clear

1:19:27 but wait a minute there are a lot of constraints here which is which

1:19:31 will be coming up when we are doing this into the real world

1:19:33 so we need to provide this information into a different way into the table

1:19:40 so the table which I created earlier into the ssms I did not

1:19:44 provided any primary key as such as you can just see I just entered

1:19:49 the information I just created this information as much simple way as I

1:19:53 could but right now I'll be giving a primary key also to this particular

1:19:58 table so let us do this now first of all uh I'll use

1:20:05 the details table only so I'll just draw this table um and this okay

1:20:31 let us create the table as details and let us insert the data

1:20:39 here when rows affected it is same so I'll just write here select star

1:20:46 from details so I'll just execute this and into this particular table I'm

1:20:56 telling the roll number is the primary key that means that I cannot have

1:21:01 repeated value so row number one information

1:21:04 the different student cannot have the wrong

1:21:08 number as one similarly no the student can have raw number is 2.

1:21:12 every student has is given a unique raw number let us see if we are able to add

1:21:19 this particular information and we'll try to see if

1:21:25 roll number is the primary key of this particular table

1:21:27 or not and if not how do we ensure

1:21:30 this so I'll just write here James with machine let's

1:21:36 say and Shane roll number is one so I'm

1:21:41 inserting this particular information let's see if this information is

1:21:45 getting inserted or not so okay it is sending

1:21:47 one row affected and just execute this particular command

1:21:52 so let's start from details so you can see

1:21:54 into the very last row the information which right now

1:21:59 I have inserted has come up and this is

1:22:01 ideally a wrong scenario no two students can have

1:22:05 the same roll number so there should be some mechanism

1:22:08 through which we can tell into our code that take

1:22:12 the raw number as the primary key of this particular

1:22:15 table and do not insert duplicate values in future

1:22:19 so we'll have to tell you to this particular

1:22:22 code so what are the changes which we need to do here so we they just a minute

1:22:28 change when you are creating the table you need

1:22:30 to mention this information that which column should be

1:22:34 the primary key of this particular table how do we

1:22:37 give this so it's very simple whenever you're creating

1:22:39 the table in the very last you need to mention

1:22:43 here primary key and into the brackets you need

1:22:47 to write the primary key column name which is

1:22:50 the problem column now first of all we need

1:22:59 to drop this particular table will create it from the very

1:23:03 beginning drop this particular table I'll just write here

1:23:06 drop table details let us execute this the tables

1:23:15 have been dropped now I'm creating a new table

1:23:17 with primary key as roll number the command has

1:23:21 been successfully executed I'll insert the details I'm doing

1:23:26 the same process again to just show you what is

1:23:29 the difference you face when you insert a primary

1:23:32 key into a particular table so I'm inserting the same

1:23:37 details into the table it has executed I'll just

1:23:42 run the selection from details to see the details

1:23:46 have been inserted or not and you can see

1:23:48 the details have been inserted now what I will

1:23:50 try to do is I'll try to add a student

1:23:53 with raw number as one again and let's see

1:23:56 what is the thing which is happening it will

1:23:59 throw an error or the data will be inserted

1:24:01 but the data will look in a different kind

1:24:02 of format so I don't know let's see what will

1:24:05 happen so I will try to insert a student

1:24:08 again with a roll number as one there is

1:24:12 a unique student this there's a unique role number

1:24:15 attached to every student so into our table from before

1:24:19 James have been assigned roll number as one now

1:24:22 what we're trying we're trying to insert our new

1:24:25 students shame as remember as one so let's see

1:24:28 if this is happening or not so I'll just execute

1:24:30 this command and you can see it has taught

1:24:33 me uh error and this is a primary key error

1:24:36 so it is saying cannot insert duplicate key in object

1:24:39 TVO dot details so friends this was the thing

1:24:42 which I was talking about so this exactly is

1:24:44 the primary key so primary key is very important

1:24:47 because it helps to distinguish every row information how

1:24:52 is every information in order is unique from the other

1:24:55 row so it will help us to uh uniquely

1:24:58 identify each row information so this is pretty much

1:25:02 clear I hope why did I choose roll number

1:25:04 as the primary key because many students can have

1:25:07 the same name so you can see here Robert

1:25:09 and Robert they were repeating so I cannot make

1:25:12 the name as the primary key also in this case

1:25:16 Robert is in the biology branch and the second robot

1:25:20 who the Royal number is seven is in the Arts

1:25:22 Branch but this can be a scenario also

1:25:24 that into the same string let's say the stream

1:25:28 is biology we can have the same name of student

1:25:33 the double dose would be two different person overall

1:25:36 but the the name of the student will be

1:25:38 saying that stream is also same but there should

1:25:41 be a unique thing to identify both the different students

1:25:43 and that is the roll number of the students

1:25:45 so friends this is the use of the primary

1:25:48 key if you will look into the details so

1:25:51 and we just saw how do we implement this practically

1:25:54 into our ssms let us move to the next

1:25:58 thing which is the not null I would just show

1:26:03 you uh into the columns so you can see

1:26:12 all these information which is coming here it is showing

1:26:16 as null uh every every other row is none

1:26:21 that means that if a person is not entering

1:26:25 any information for those particular uh columns leave it

1:26:30 as null what does that mean right now you can just see here if I do a selection

1:26:36 from details every Inner Cell has a certain value attached

1:26:40 to it but what if I will just tell it

1:26:45 that the raw number column in every row information should

1:26:51 be present it should not be null so let us try to see this I would not enter

1:26:59 any value for the roll number column adding

1:27:03 to the first name column and into the last name column

1:27:13 I would have certain values let's execute this quality

1:27:16 a command now before that uh I would drop

1:27:23 this particular table because we have set primary key

1:27:28 as a roll number I don't want to do this because

1:27:31 there would come up and I won't even show

1:27:34 you what exactly is not null so I'll just

1:27:36 execute make the table once again I'll insert the data

1:27:39 this time I'll insert the data with an additional

1:27:43 row you can just see here and I haven't

1:27:45 entered any value years I'll just execute this okay

1:27:50 there's some syntax error so instead of and just

1:27:53 put it as simple string I'll insert this particular data

1:28:03 or instead of string let me give simple num

1:28:08 and uh insert the data finally let us see how

1:28:14 the data looks like interesting 11 rows affected I'll

1:28:17 execute so you can see it's coming out as null

1:28:19 and the wrong number column cannot be null because

1:28:24 the example which I gave earlier is let's say

1:28:26 two students have the same name and they are

1:28:29 running to the same string they should have something you

1:28:32 need to distinguish them the student here is having

1:28:35 a roll number as 10 and the second student

1:28:38 roll number is null and this is a very

1:28:42 wrong data which has been inserted here so this should

1:28:45 be some way through which we can just say

1:28:47 that the user if is not giving or giving

1:28:52 a null value it will not accept it it will

1:28:55 only accept when the information is filled into that particular

1:28:59 column so to make this sure we'll have to enter

1:29:03 a command which is the not null this will

1:29:07 ensure that every information is entered and there is

1:29:12 no information which is coming as null for this particular

1:29:15 column so I'll just run this particular drop details

1:29:19 I'll recreate the table here the table has been

1:29:23 created I'll rerun this command again with the null

1:29:27 value and let's see what is the error which

1:29:30 is coming up and it is selling cannot insert

1:29:32 the value null into the column the roll number

1:29:35 because it doesn't allow nulls it is mentioned explicitly

1:29:39 that it should be a not null column so we

1:29:42 will have to provide a value there to insert

1:29:46 the value so right now that data would not

1:29:49 have been inserted I'll just show you you can

1:29:51 see the entire table is empty so I'll just put

1:29:55 a raw number to this and I'll now try it and you will see that it is executed

1:30:05 successfully and it is now showing the details also

1:30:11 so friends this is all about the not null concept

1:30:15 we can give the student name also has not

1:30:20 another right now let us let us show you

1:30:26 an example a similar kind of example I'll I'll not

1:30:30 enter the student's name it will be none and just

1:30:36 enter the ID and I'll execute this let us

1:30:41 see if the data is getting inserted or not

1:30:43 definitely it will be inserted and this is also

1:30:47 a very wrong information which you'll be getting as you

1:30:51 can see here null is coming in the student's

1:30:54 name so friends this should not happen so

1:30:58 for this not to happen I'll provide a not known

1:31:02 condition here again I'll drop the table once more let

1:31:07 us create a table again I'll insert the values

1:31:12 into this particular table with a null value let

1:31:16 us see if it throws an arrow it is only a error so instead of null I should give

1:31:22 a name to this particular student and let us

1:31:25 try it right now we are getting to insert

1:31:27 the values of the student I'll execute this we're

1:31:32 showing 12 rows affected I will execute selection from details

1:31:36 and you can see the details have been inserted

1:31:40 now friends let's do one thing I'll just run

1:31:44 this command once again insert into it is saying

1:31:48 dual rows insert affected and I'll execute this now you

1:31:52 can see the data is getting added up

1:31:55 from the previous data which we are having into our table

1:31:58 from before until and unless we are dropping the table

1:32:01 so dropping means deleting the table entirely and then

1:32:05 recreating the table from the very beginning but when

1:32:08 we I'm just reinserting inserting data every time it

1:32:11 is inserted or added to the previous data now

1:32:15 here you can see two students are having the same

1:32:17 roll number of the data is getting repeated

1:32:19 to avoid this particular thing in which we have talked

1:32:24 about is about the primary key so we'll just

1:32:28 write here primary key I'll mention the primary key

1:32:31 on this particular table which is the raw number

1:32:33 let us do the same thing again I'll execute

1:32:36 this but you know command I would execute the table

1:32:41 details I'll insert the details execute this you can see

1:32:50 12 rows are effective I'll do a select chart

1:32:52 from details you can see I'm getting all the information

1:32:55 let me try to reinsert data again and let's

1:32:58 see I've given the primary key as the roll number

1:33:01 and it should not duplicate again so I should

1:33:04 throw an error to me I'll execute this command

1:33:06 and you can see it is showing me a error

1:33:08 that the duplicate key values are coming up so

1:33:11 friends you can see such powerful is equal and using

1:33:15 it will not if you're using the right commands

1:33:18 at the right time for the right thing it

1:33:20 will allow you to save the right data and so

1:33:25 I'll just do select start from details and you can see no data has been added it

1:33:29 in just the same data which is present from before

1:33:31 and if a new ID comes up let's say

1:33:34 a 30 round number 13 is not present and I want to insert all over 13 I'll run

1:33:39 this and I'll execute this you can see one row

1:33:42 effect in and the 13th role number student details would

1:33:46 have been added as you can see into the last

1:33:48 two the information is pregnant so when this is

1:33:51 all about the primary key not null information right

1:33:56 now this is not refreshed so it is not showing as it is showing us null but uh

1:34:01 you do one thing you just close your system uh

1:34:04 sorry you close your ssms right now reopen it

1:34:07 once again and you will be able to see all

1:34:10 the information let me see if it is refreshed

1:34:13 or not okay I'll just take the refresh and you

1:34:15 can see the thing which I was talking about

1:34:18 I am having all the information the key symbol

1:34:20 has been come up and this is the primary

1:34:23 key the analysters do not know similarly the student first

1:34:27 name should also not know that has also come

1:34:29 up so from this is the power of the ssms

1:34:32 you are getting all the information you are seeing

1:34:34 all the information clearly whatever you have done so

1:34:38 the information is not getting overloaded but there are

1:34:40 a lot of things to uh capture a lot of things these are some of the basic things

1:34:45 we should definitely know when a solid will not sequel

1:34:48 you these are asked into the interviews are a lot

1:34:51 of many times friends let us see one more

1:34:53 thing which is the auto engagement now why Auto

1:34:57 Implement is useful and why do we use it

1:34:59 auto increment is used basically let's say this is

1:35:03 the roll number column by mistake uh when we are

1:35:07 entering data manually there might be a case

1:35:11 that we will be entering uh multiple duplicate values so

1:35:15 let's see if if I'm not using the primary

1:35:17 key I might add duplicate values duplicate problem or values

1:35:21 into my table Auto increment is one of the feature

1:35:24 through which you don't need to mention the column

1:35:27 uh details when you are inserting data into the column

1:35:30 you just write their Auto increment and it

1:35:33 will be automatically it will increment by plus one

1:35:37 plus two whatever you want so and the syntax is

1:35:40 also very much simple so to do this I

1:35:43 would first of all draw the table so Auto increment

1:35:47 is basically a term which is used in my SQL

1:35:50 similar in the same concept is here it

1:35:53 is termed as identity I'll just write here id10

1:35:57 if and into this identity you need to provide brackets

1:36:04 and into this bracket you want to provide the information

1:36:07 information as in how will the values will be

1:36:10 Auto incremented so let us say the wrong number

1:36:14 column is starting with 1 and by what steps it

1:36:18 should Auto Implement so it should Auto increment over

1:36:21 step as one so the values will be provided

1:36:24 like one two three four five six seven eight

1:36:26 and again so all this information will present like

1:36:30 this since even if we don't provide this roll

1:36:33 number one two three four our values will be inserted

1:36:37 so I'll just delete all these values from here

1:36:41 the role number values so let's create this particular table

1:36:59 command executed successfully right now you can see

1:37:03 I don't have I'm not giving the wrong number

1:37:05 of column also I'm not inserting any values so

1:37:08 with the help of the identity it will auto increment

1:37:11 on itself automatically every row will be provided

1:37:16 a unique information so I'll just do a select start

1:37:19 from details and you can see even if I did

1:37:22 not give any raw number uh it has been giving

1:37:26 the details as one two three four five six

1:37:28 hundred nine ten now this identity let's say instead

1:37:33 of one two three four I want to give

1:37:36 him to the odd numbers so I'll just write here

1:37:40 2 instead of one and we run this particular

1:37:44 details I'll insert into details as well and I'll

1:37:51 go select start from details and you can see

1:37:53 the roll number column the values are coming as one

1:37:57 three five seven nine so this is how

1:37:59 the identity function or the auto Implement function is working

1:38:04 oh you can see here I've added the primary

1:38:06 key as the roll number also let us refresh once

1:38:10 again here let us see if something comes up

1:38:15 for identity or not and nothing as such is coming

1:38:18 for identity but it is working correctly so friends

1:38:22 we have a lot of information we learned a lot

1:38:25 of things on how do we create table how do we insert information how do we give

1:38:30 a primary key for a particular table uh you

1:38:33 know how do we give Auto increment or identity command

1:38:37 to a particular table when we are creating it

1:38:39 how do we make sure that a user is not

1:38:43 leaving a null value or just not keeping any value

1:38:47 for a particular column how do we ensure that we

1:38:50 ensure that using not null functions so friends all

1:38:53 of these different things we learned right now now

1:38:57 so let us move to the next information which

1:39:00 is present here and which is the surrogate key we

1:39:05 learned about the primary key this is the surrogate

1:39:07 key survey key is nothing but so any primary

1:39:12 key column which we give like the raw number

1:39:14 ID column uh so every raw number is a simple

1:39:19 a random thing which we are providing such

1:39:21 as one two three four five six seven eight nine

1:39:24 ten it does not have a real meaning

1:39:26 into the world so it is just random number which is

1:39:30 which I'm picking up I could have also picked

1:39:32 up the alphabets instead of one two three four so

1:39:36 these are the examples of the surrogate key so

1:39:40 surrogate key is any random ID for the primary key

1:39:43 let us move to the next which is the natural

1:39:46 key so natural key is something choosing a key

1:39:50 which has a real purpose so the example which

1:39:53 I gave about the aadhaar card so every person

1:39:56 has a unique aadhaar card number so even if

1:40:00 multiple person have the same details they will have different

1:40:03 other hardcore details so this is an example

1:40:06 of the natural key a natural key has a real life

1:40:09 purpose actually the your radhaar card number is has

1:40:12 all the details attached to you so it has a real life purpose so this is called

1:40:17 as a natural key let's move to the next next is

1:40:22 the foreign key now what is a foreign key a foreign key is basically you can see

1:40:28 into this particular example I have two tables table one

1:40:32 and table two into table one I have the all

1:40:36 number into the second column uh the name

1:40:40 of the student and into the third column are the stream

1:40:43 ID and I have another table into the First

1:40:46 Column I have the stream ID and into the second

1:40:49 column I have the stream name now friends what

1:40:52 if we want to generate a result where we

1:40:56 have an information such as roll number name stream

1:41:01 ID and name of this field so the information should

1:41:04 be something like number name stream ID and stream

1:41:14 name so this is the output which we want

1:41:20 to have now what are the tables which we

1:41:22 are having we are having tables such as wall number

1:41:27 name and Swinging ID to the second table I

1:41:32 have the extreme name and stream ID now friends

1:41:40 into this particular table the primary key is the wrong

1:41:43 number because every student will have a unique problem

1:41:45 number similarly into this particular table let's say

1:41:49 the stream ID is the primary key that won't matter

1:41:51 the thing which we're talking about here is the foreign

1:41:54 key now what is the foreign key a foreign

1:41:56 key is particularly a particular column for which you

1:42:01 will be joining or getting information from the other table

1:42:04 so friends let's say if I want to get

1:42:06 this stream name here so into this particular example we

1:42:11 saw the ID column is the foreign key so the ID stream ID column is a foreign key

1:42:18 into the table one because through this we will

1:42:21 be getting the information Concept in SQL which is

1:42:24 join so we can just join multiple tables if

1:42:27 they are related to in some or the other

1:42:29 way so you can join them and get your desired

1:42:31 results so we'll come back we'll get to know

1:42:34 that into lot of more details later on but basically

1:42:38 the concept is available simple that two tables you

1:42:41 will have to join on what column you are

1:42:43 joining them that column is kind of the foreign key

1:42:47 of that particular table so through which you will

1:42:50 be joining a foreign key foreign key for a particular

1:42:53 table could be the primary key for the another

1:42:56 table so you can see here the stream ID is

1:42:59 the primary key of this particular table while

1:43:02 for this particular table this ID is a foreign key

1:43:05 so friends this is uh all about the foreign

1:43:08 key I hope you are able to get it just

1:43:11 basically uh for join two different tables we are

1:43:14 using a particular column we can call that column

1:43:16 as a foreign key column and of foreign key

1:43:20 column can be a primary key column in a different

1:43:23 table about the foreign key let us move

1:43:29 to another thing which is the composite key what is

1:43:32 the composite e to various situations basically you won't

1:43:37 be able to have a particular column to which you'll

1:43:42 be getting a unique value so you know this particular

1:43:46 case you can just see I have the information into the column A I have the class

1:43:51 of the students into the column B I have the name

1:43:54 of the student in the column CI the contact

1:43:56 number of the students into the column D I

1:43:59 am history ID of the students now you now

1:44:02 if I tell you to clearly see whether if you

1:44:06 can find unique values into any of this particular

1:44:13 columns you cannot because you can see pipe is

1:44:17 being repeated five is present here five is present

1:44:21 here five is present here so this particular column cannot

1:44:26 be a primary key for this particular table similarly

1:44:29 you can see Robert Robert the same name is

1:44:32 coming multiple times so this cannot be a primary

1:44:34 key of that particular column also similarly contact numbers are

1:44:39 also getting repeated you can see the same contact

1:44:43 number is coming from multiple students so this can be

1:44:48 considered as the parents contact number so there might

1:44:51 be case that the students are siblings and that is

1:44:54 why the parent contact number is the same

1:44:58 and the stream ID basically or this definitely will be

1:45:01 same so you can see one one is coming

1:45:03 four four are coming two times so in this case

1:45:06 how do we get to a solution that will

1:45:10 be forming a primary key so primary key need

1:45:12 not necessarily be from a single column we can

1:45:16 combine multiple columns to make the primary key and when

1:45:20 we are combining multiple columns to make a primary

1:45:23 key that was termed as a composite key

1:45:25 and that is all about the composite keys so friends

1:45:28 you can see here if I just join the name

1:45:31 of the student with the contact number that would

1:45:35 form the composite key into this particular case let us

1:45:39 execute this particular thing in our SQL Server management

1:45:43 studio and let's see this practically if and how is

1:45:47 this happening so let us insert these details here

1:46:22 I have not given any primary key for this particular

1:46:25 column expected the values have been inserted as I

1:46:28 discussed that the student name and the contact number

1:46:32 can somewhat form a primary key because uh

1:46:36 a student will have a unique ID or a unique

1:46:40 contact number as to his name so that can

1:46:44 be composed as a primary key for this particular table

1:46:46 and that would name as the composite key so

1:46:51 let us try to insert value into this particular

1:46:55 table in which I would give the different class

1:47:07 the name would be shown the stream ID would be

1:47:12 saying and the number also will be same so

1:47:17 I'll just insert this into details who was effective

1:47:23 is telling as we discussed that I will just

1:47:28 copy this into the Excel so this was the class

1:47:44 this was the name this was the phone number

1:47:50 this was these three difference uh as I discussed earlier

1:47:55 that the name and also the phone number they

1:48:06 are the primary keys so according to that the combination

1:48:08 should not be duplicated into any other rules

1:48:11 but here you can see the combination is duplicating so

1:48:14 to make this as a primary King both of these columns is a primary key so we need

1:48:21 to provide this into our code so that in future

1:48:25 none of this kind of data would be inserted

1:48:28 so to make two columns as a primary key

1:48:31 I would just write here primary key and I need

1:48:39 to mention both the column names to the name

1:48:45 from our contact number that's all I'll do one thing

1:48:51 I'll proactive details I will create this table again

1:48:57 and I would if reinsert this data right now what

1:49:01 I have given is I will when two columns

1:49:04 as the primary key let us see the details

1:49:08 from here you can see I have all the details

1:49:12 which are present here I'm inserting James with the same

1:49:16 phone number and robot with the same phone number

1:49:19 let us see when we have given the composite

1:49:22 key as the student name and the contact number

1:49:25 we are able to insert this information or not

1:49:27 or if it is showing error so you can

1:49:29 see it is giving the duplicate key value error

1:49:32 and this is meant that we are we should

1:49:36 be getting a duplicate error because we are entering

1:49:38 the same combination so the combination as in the name

1:49:41 of the student and the phone number if you

1:49:44 just look at the combination which I was talking

1:49:47 about that should not be a student so two different

1:49:51 students cannot have the same name and the same

1:49:53 phone number uh in a scenario but let's say

1:49:56 in a class there are there are two students

1:49:59 who are having the same name also and they are

1:50:02 having the same phone number let's say they are

1:50:04 siblings so in that case we will be needing

1:50:09 to have some another column which would serve as the primary

1:50:12 key column that could be let's say the wrong

1:50:15 number of the student but with the limited amount

1:50:18 of information which we had so I had to make

1:50:20 you understand what is the composite key basically

1:50:23 in this combination of one or more two or more

1:50:25 columns to make the primary key so through

1:50:28 this particular combination whatever the key pair which we get

1:50:31 is forming the composite key of the particular table

1:50:35 so friends this is all about the composite pillars move

1:50:39 to the next section Friends next we'll be discussing

1:50:41 a very important topic in SQL which is the SQL

1:50:45 operators now there are various other operators which are

1:50:48 present into SQL will be discussing them into lot

1:50:51 of more detail mind you I'll be discussing all

1:50:54 the operators which are present in SQL so you

1:50:57 need not to study anymore from what I'll be

1:51:01 discussing into this particular video so let us move

1:51:04 on to my next screen so there are basically

1:51:08 you can see onto my screen all the operators which

1:51:11 are present into the SQL so we have the equal

1:51:14 to we have greater than greater than equal to less

1:51:18 than less than equal to and not equal to we

1:51:21 also have this where clause and are not Clause

1:51:26 so we have all of these different operators which

1:51:28 are present into SQL now now equal to is very

1:51:31 much clear so when any variable is equal to some

1:51:36 uh particular number or any you know let's say

1:51:39 a particular string so we'll be using this particular

1:51:42 equal to sign so if I would have to explain

1:51:45 this into the Excel so I'll just quickly go

1:51:48 on to my Excel sheet and then we'll be seeing in this into detail on to our SQL

1:51:54 Server management Studio first of all the very first operator

1:51:57 was equal to operator so let's say 5 is equal to 5 so what does this or gives

1:52:06 into the output just hit the enter button so

1:52:10 you can see it is giving me a screw so

1:52:14 when both of these what we are comparing is

1:52:18 is equal so and when we are hitting the enter

1:52:22 button you can see it is giving me as true now let me give 5 is equal to 6.

1:52:27 now what do you think what this should uh give into the output so as uh you

1:52:32 know this is giving is it as false because 5 is not equal to 6 so this is

1:52:37 the use of the equal to sign now let us move to the greater than sign so

1:52:42 I'll just give here 5 is greater than 6 so what do you think what this should

1:52:49 return so you can see this is returning as false because uh 5 is actually not

1:52:55 greater than 6 it is 6 which is greater than 5 so if I would just reverse

1:53:01 the sign so I'll just write this 6 is greater than 5 and I'll hit enter you

1:53:05 can see it is returning me a true now

1:53:08 greater than equal to the third operator which I

1:53:11 was present greater than equal to let us

1:53:13 see well just write here 5 is greater than

1:53:18 five what do you think what this should

1:53:21 return so this should return a false because 5

1:53:25 is not greater than 5 so but when I

1:53:29 write here greater than and equal to this would

1:53:32 return a True Value because because of this equal

1:53:35 to sign also 5 is becoming equal to 5 and that has particular criteria is

1:53:41 satisfied that is why it is returning a true

1:53:44 value now moving to the next is less than so I'll just write here 5 is less

1:53:50 than 6 and this is also true so because 5 is actually less than 6 so it

1:53:58 is returning as true similarly less than equal

1:54:01 to signs of 5 is less than equal to 6.

1:54:04 what do you think what this should give up into the answer this should

1:54:09 also give up a True Value because 6 is actually greater than 5

1:54:15 so this particular condition is satisfied now

1:54:17 instead of 6 I'll be mentioning year

1:54:20 5 which particular condition is satisfied here it is the equal to sign which

1:54:25 is being satisfied here so that is why we'll be getting True Value

1:54:28 here so when this was all about to be equal to greater than equal

1:54:32 to less than equal to now these things

1:54:34 you might be familiar with these particular

1:54:37 things but I just wanted to bring this out so that uh some

1:54:40 of your Concepts will be getting cleared if if you might not be knowing

1:54:44 this particular thing so I'm just doing

1:54:46 this particular course from the very scratch

1:54:48 level from the very basic level so even if you don't have any knowledge

1:54:52 of SQL completing this course will make you interview ready that is for sure

1:54:57 because I've covered almost all the topics

1:55:00 hundred percent of the topics into this particular

1:55:02 video which is generally asked nowadays into the analytics interview for the SQL

1:55:08 now let us move to the next operators which are present here which is

1:55:12 the not equal to sign so not equal to from the name only it

1:55:18 is very much clear so 5 is equal to 5 this would return it

1:55:21 true but if I want to compare two different values and with they are

1:55:25 not equal so how should we write that what is the Syntax for that so

1:55:29 the Syntax for not equal to is something like this let us hit

1:55:33 the enter button you can see it is returning a false because 5 is

1:55:39 equal to 5 mind you into the Excel not we can write the not

1:55:43 equal to sign like this also so that is why the not equal

1:55:47 to sign has changed with this particular sign which you can see onto your screen

1:55:52 let us move to the next thing which is the where Clause now it's

1:55:56 coming back to where Clause so you can see I have a data set

1:56:00 ready which in front of my screen now from this particular data cell let

1:56:05 us say I want to filter out all these students I want to get

1:56:08 the details of all the students with name as Robert so what I'll

1:56:12 be doing so I'll be first of all applying the filter thing here so

1:56:17 you can apply the filter the shortcut is Control Plus shift plus l so

1:56:22 after after applying the filter thing all

1:56:24 the alternate method is something like uh

1:56:27 you need to go to this particular filter section and then select the filter

1:56:31 thing so you can see the filter thing has been applied now what

1:56:36 do I want to get I want to get the details of all

1:56:39 the students whose name is Robert so from this particular column I want to first

1:56:46 of all open the filter section and then I would just want to get

1:56:49 the details of the student whose name is Robert I'll just select this and you

1:56:55 can see I've got the student details whose name is Robert so I'll just

1:57:00 copy this I'll paste this somewhere else so you can see from this particular

1:57:04 entire set of data I just wanted to get the details of the students

1:57:09 whose name is Robert so I've just filtered out the relevant information

1:57:14 from this particular set of data and this is my result which I wanted

1:57:19 so this was my you can say the entire data set and this is

1:57:25 the subset of this particular entire set of data which was present so I

1:57:31 just wanted to get the details of all the students whose name is Robert

1:57:35 so I've got the relevant details so friends uh this is how the filter

1:57:39 thing works similarly a similar concept is present into a SQL which we do

1:57:47 with the help of where plus don't worry I'll be doing the same thing

1:57:51 using the bear clausing to the SQL so that you get complete understanding I'm

1:57:56 just explaining right now onto the Excel

1:57:58 because it is far more better understanding

1:58:01 here and then we'll be implementing the same thing into our SQL our ssms

1:58:07 software so this is the first application of the wear class now friends

1:58:12 let us say I want to get the details of all these students whose

1:58:17 name is equal to Robert and the stream is equal to 2 equal

1:58:24 to 2 sorry so how do we go about this because there are two columns

1:58:29 on which I we need to apply filters so how do we go about

1:58:33 this into the Excel so the same thing first of all I'll be applying

1:58:37 the filter thing here the first filter

1:58:39 condition so there are two different condition

1:58:41 as you can see here the very first condition is the name is equal

1:58:45 to Robert so the very first filter condition I will apply here as robot

1:58:52 the second filter condition was the stream should be equal to two so

1:58:56 from this particular section you can see the stream should also be equal to 2

1:59:03 so I'll just select here Robert and the stream should be equal to 2.

1:59:11 so this is the information the exact information which I wanted I've

1:59:17 got the relevant information here so I'll just do one thing I'll copy

1:59:23 this I'll paste this here because this was this was my entire set

1:59:27 of data and this the the result which we have got is the subset

1:59:32 of the data or the desired information which I require we wanted to get

1:59:36 the details of all the students whose name is Robert and the stream

1:59:40 is able to do so this is the information which we have

1:59:43 got this is how we filter out the relevant information into the Excel

1:59:48 the same application we do into the SQL with the help of the where

1:59:53 Clause now coming back to the next operator which is present here

1:59:57 which is and or M naught so and operator how does and operator

2:00:03 work I'll help you understand this with the help of examples so let's say

2:00:08 uh one we have two different variables so I have column A and next

2:00:16 thing I have column B so I have certain values which are

2:00:20 present here so I'll just take a 0 0 1 0 0 1

2:00:31 and one one let us say all these values are present into the uh

2:00:37 our our data set so into one of the column I have

2:00:41 a into the other column I have B and all of these values are

2:00:44 present now how does and condition work this is for two variables there

2:00:50 can be as many as variables as possible they do remain the same just

2:00:55 remember the rule how the and condition works that will be it

2:00:59 and that is how you'll be getting to know how does these things work

2:01:03 and you will be applying into the SQL Server we'll be doing this don't

2:01:06 worry practically into our ssms I'm just helping you to explain this much

2:01:11 more better into the Excel now how does this and condition work so

2:01:14 I'll just tell you the things which you are comparing each and every

2:01:18 condition if it is equal to true so you will be getting a true

2:01:24 value so into this particular thing you can see both of these zero

2:01:30 so let us assume that 0 is equal to false here and 1

2:01:36 is equal to True let us assume this for now now if both

2:01:43 things which you are comparing so both the things we are comparing here

2:01:46 is a and b you can compare as many as variables as possible

2:01:50 as many as columns as possible there can be 100 columns 200 columns

2:01:55 you are just comparing so let's say the columns which you're comparing if

2:02:00 both the values are false the result which you get is false when

2:02:04 you are applying the and condition even if one of the condition is true

2:02:13 and the other condition is false you'll be getting a false let's say

2:02:19 you're comparing five different variables the four become true even if one is

2:02:25 false it will be false when you are applying the and condition because

2:02:29 for and to be fully successful to give a True Value all the conditions

2:02:35 should be met that is the advantage of using the and variable

2:02:39 or that is how the and operator works everywhere so you can see here

2:02:44 Z into the a column I have 0 into n into the B

2:02:48 column I have one so here you can see this is becoming as false

2:02:53 so even if one is becoming false in the and operator the result

2:02:57 will be false now coming to the last you can see into a it

2:03:02 is present as 1 M into B it is present as one

2:03:05 both are true so the things which we are comparing of the variables

2:03:10 which we are comparing if all of them are true the result which

2:03:13 you will be getting is uh true so here we'll be getting a one

2:03:17 so this is how the and operator works so the next which is

2:03:21 the or operator so into the OR operator it works exactly the opposite

2:03:27 of the and operator enough or operator even if one is true the result

2:03:32 which will be getting is true the only condition to give our True

2:03:37 Result for the or operator when you are comparing uh let's say many

2:03:41 variables so only condition is one of the variable one of the condition

2:03:46 should be equal to true now into this particular case you can see

2:03:50 Zero and zero both are false so in order for or operator we

2:03:54 need to have something which is true here you can see both are

2:03:57 false so this should be zero now coming to the next you can

2:04:01 see in a it is one in B it is equal to zero

2:04:05 so you can see in B it is false but for a it

2:04:08 is getting true so in our operator at least one should be true

2:04:11 and this is happening so the result which we'll be getting will be 1.

2:04:15 coming to the next you can see here into a and b b is equal

2:04:20 to one so at least one we are waiting as a True Value so this will be

2:04:25 a one and into the next thing you can see both are one so at least means

2:04:31 minimum one value should be satisfied or one

2:04:34 value should be true more than one we need

2:04:36 not care or will be satisfied if one of the condition is true so it only

2:04:41 cares about that so you can see both

2:04:43 of the conditions are true so it will definitely

2:04:45 be true so friends this is how exactly

2:04:49 the and and or condition works you can just

2:04:53 uh if you are having any issue you can just comment down your doubts but this is

2:04:59 exactly how the and and the or operator

2:05:01 Works friends I hope this particular logic

2:05:04 or this particular concept is very much clear you

2:05:06 can just stream behind this particular video and then

2:05:08 re-watch it once again if I have to just summarize the and and the or operator

2:05:15 the is something like for and to be you

2:05:18 let's say you're comparing n number of variables n

2:05:21 number of columns n number of conditions you

2:05:24 are just comparing even if one condition is

2:05:27 getting true in the and operator the result

2:05:30 will be false for and to be successful

2:05:33 for and to give a result as true each and every condition should be true that is

2:05:38 the uh the condition for the and operator while

2:05:42 for the r operator at least one condition if

2:05:45 it is getting true the result will be

2:05:47 true while for and condition every condition should

2:05:50 be true then the result will be true and for the or operator at least a one

2:05:55 condition should be true then only the result

2:05:57 will be true so friends this was all about the and and the or operator the next

2:06:02 operator into our section is the not operator now

2:06:06 friends this is very interesting just let's just say 5 is greater than 3 so what

2:06:11 should be the result the result should be true now let's see if I add a not

2:06:17 operator here and I'll just give you a not of proof what do you think what

2:06:23 this should return Yes this should return as false

2:06:26 because not operator the function is it will return

2:06:30 the opposite of the expression which you are

2:06:33 giving inside the not operator so you can

2:06:36 just see here how the flow was the flow or something like I had two numbers I

2:06:41 compared both the numbers whatever the result may

2:06:44 be let's say 5 is greater than 3

2:06:46 yes it is greater than 3 so the result was true now into this true I applied

2:06:52 the not operator not of true so in not operator it will give the result which is

2:06:58 opposite of the expression which you are giving

2:07:00 into the not operator so not of true what

2:07:03 is the opposite of true the opposite of true

2:07:05 is false and that is the result which we are getting on to our screen you

2:07:10 can just see so the not operator is something

2:07:13 like not of 3 greater than five so what do you think what should be result

2:07:18 here uh just pause this video think about

2:07:21 the result of this particular expression is true I

2:07:25 hope this is this thing is pretty much

2:07:27 clear now friends this was all about the SQL

2:07:29 operator C into the or ssms how each of these things are working and how do we

2:07:35 operate into each of these things so friends

2:07:37 you can see onto my screen from our code we have created this details table one

2:07:45 by one we'll just see how these particular operators

2:07:48 they work the very first thing which we saw

2:07:50 was the equal to condition and the the output

2:07:53 which we required is the name of the details of all these students whose name is

2:07:58 equal to Robert so how do we write

2:08:01 this into the SQL so we replied this something

2:08:04 like select star from details and here one thing which I would like to say is

2:08:16 the use of the wear operator so if

2:08:19 you just remember I was filtering out the results

2:08:22 here I was applying the filter function

2:08:24 from the Excel and I was filtering out the result

2:08:27 you can just think on this similar lines now I want to filter out a result

2:08:34 from the entire set of results which I have I want to filter out the result

2:08:40 or the information which I want the what is

2:08:43 the information which I want I want to get

2:08:45 the details of all the students whose student

2:08:48 name is equal to Robert so friends you can

2:08:51 just see select star from details I'll just

2:08:54 apply a where Clause so I'm just telling where I'll just write a student name is

2:09:02 equal to something and do that something you can

2:09:05 see here I am using the equal to sign so what is that something the something is

2:09:12 raw part so I need to provide it exactly how it is into my data set so

2:09:18 you can just see here R is capital I have given R into capital and while

2:09:22 the other characters they are in small so I need to provide them in two small so

2:09:27 it shouldn't match exactly how it is

2:09:30 into our data set then only we'll be getting

2:09:32 into the output so I'll just select this code

2:09:35 I'll just execute this so you can see I'm

2:09:37 getting two results and into our data set into a details table you can just see

2:09:44 two students are there name is Robert and all

2:09:48 those student details I am getting it right

2:09:51 here on to my screen now friends I let's say I want to see how does

2:09:57 the greater than sign work so let's say

2:10:00 from this particular data set I want to get

2:10:02 the details of all these students who studies

2:10:05 in class 6 and greater than classic so above

2:10:09 classics all the student details I want so

2:10:12 how should bigquery look like so the query should

2:10:15 look like something select star from details where

2:10:20 you can see a class column so under the class column I'll be applying a filter

2:10:24 and what should be the filter condition the filter condition

2:10:26 is something like I want to get the details

2:10:28 of all the students who studies in class

2:10:32 6 or greater than class six so I'll just write here equal to greater than class

2:10:38 6 that's all I would execute this particular

2:10:42 command and you can see I'm getting the details

2:10:45 for all the students who are in class 6 and greater than class 6 if I

2:10:51 would just have to verify this I will

2:10:53 just rerun the entire data set and the result

2:10:57 set which we have got so you can see I am getting the correct results I

2:11:04 am getting all the desired result the result

2:11:06 of the students who are studying in Classics

2:11:09 or greater than class six the similar thing let's

2:11:11 say I want to get the details of all

2:11:13 the students who are studying in class six or less than class six so what do I

2:11:19 need to do I would need to change the sign so less than class 6 and equal

2:11:23 to class six that is the query which

2:11:27 I should write I'll execute this particular command

2:11:29 and you can see I am getting all

2:11:31 the details of the students who are studying in Classics

2:11:34 or less than classic so friends this is

2:11:37 how we are utilizing the SQL operators and we

2:11:40 are operating into them into the ssms

2:11:44 but friends let us move to the next operator

2:11:46 which was there now you have seen this very

2:11:51 close how are we utilizing the weight loss

2:11:53 now one more thing this not equal to sign okay let's do one thing I would do

2:12:00 here only so I want to get the details of all the students whose name is not

2:12:05 equal to Robert so I'll just write here

2:12:07 not equal to Robert I'll execute this particular command

2:12:11 execute this particular command and you can see

2:12:13 into the output I'm getting the details of all

2:12:16 the students whose name is not equal to router

2:12:19 to the next which is the and operator

2:12:22 now how does this particular and operator works

2:12:26 now from this particular query of the students

2:12:30 whose name was Robert you can see here let's say I want to get the details

2:12:36 of the student whose name is Robert and who's who studies in class six so both

2:12:43 the conditions should match so how should we go

2:12:46 on this so we should write something like where

2:12:49 student name is equal to robot and class is equal to 6 so for and condition

2:12:55 to be giving the True Result or the right

2:12:59 result both the conditions should match both

2:13:02 the conditions should be true so by both

2:13:04 the condition I mean all these two conditions which

2:13:07 I have given right now so if any

2:13:09 record is present onto my set which satisfies both

2:13:13 of this condition will be getting those rows

2:13:16 into our output so if you would just think

2:13:18 of we did a similar thing into the Excel from this entire set of data I just

2:13:23 filtered out the information of all the students

2:13:26 whose name is Robert and the stream ID is equal to two that's a similar thing so

2:13:30 you can just see all these conditions were satisfied

2:13:34 for both of these row entries so

2:13:36 into the output we just caught both of these entries

2:13:40 here you can see I want to get this the details of the name of the students

2:13:45 whose name is equal to Robert and the class should be equal to 6 so I'll

2:13:49 just execute this particular command you can see

2:13:51 I'm getting a particular result now from this particular

2:13:55 result set only let's say I want to get the details of the students whose name

2:14:00 is equal to student and class is equal to eight so if do we have a condition

2:14:05 or a row which satisfies this particular condition

2:14:08 you can see into the output I'm not getting

2:14:11 any details because there might be a student

2:14:14 whose name is equal to Robert you can see

2:14:16 these two entries but if you'll just see the class of both these students is six

2:14:22 and five so none of the records match so that is why we are getting here zero

2:14:30 record because for any condition to give some

2:14:33 output all the condition should satisfy now friends

2:14:37 this is the magic here if I replace and with or what do you think what should be

2:14:42 the result which I'll be getting I'll be

2:14:45 getting two rows because for all condition to be

2:14:48 satisfied to give a result at least one

2:14:52 condition should be true you can just see

2:14:54 here there was no student there is there

2:14:56 are students whose name is equal to Robert which

2:14:59 is there into our data set so this condition

2:15:03 becomes true that is exactly what is required

2:15:06 just the any any of the conditions should be true we'll be getting the result

2:15:10 into our data set so it will not check

2:15:13 in this condition also so it will just give

2:15:16 out the result so it will only check if both the conditions are met or both

2:15:22 the conditions are satisfied for those condition also

2:15:25 it will give the result so the same logic

2:15:28 applies here what I discussed so for our condition

2:15:32 if both the conditions are all the conditions

2:15:34 are is equal to True into the output we'll be getting the answer as true so

2:15:40 friends this was the uh the summary or all about the and and the or operator let

2:15:47 us see an example of not operator so I'll just write here not not of Plus equal

2:16:09 to 8 I'll just execute this so you can see here I'm getting okay instead of I'll

2:16:25 just give here as not of class equal to 6 so from our data set what

2:16:33 is the result which we are getting so

2:16:35 if you will just clearly observe the result which

2:16:38 we are getting is something like we are

2:16:41 getting the details of all the students who are

2:16:45 not in class six so apart from class six we are getting the details of all

2:16:50 the students so this is the use of the not

2:16:52 operator so it will give the result which

2:16:54 is opposite of the the condition or the expression

2:16:59 which you are giving so the same result

2:17:00 which we're getting right now we could have

2:17:03 got by where class is not equal to 6.

2:17:09 so I'll just execute this particular command and you can see I'm getting

2:17:12 the same result so this is how exactly the not equal to and the not

2:17:17 operator works so what I've explained to this particular Excel sheet that was

2:17:21 quite clear and that is enough to help you understand the difference

2:17:24 between all of these different operators so friends let's move to the next

2:17:29 screen I have some more operators ready here so I have between I have

2:17:34 is null uh in distinct average count Max Min sum so this can

2:17:40 be considered as something like more of a function than operators but uh we'll

2:17:45 be discussing all of these into a lot of more detail and how

2:17:48 does these different operators they behave

2:17:51 in when we Face some complex situation

2:17:54 but right now we are just concerned about understanding all of these operator

2:17:58 into a simple way into a lot of more depth how do they perform

2:18:04 how do they behave Detention of this particular section is just to make

2:18:08 you aware about all of these operators so let us move to the between

2:18:11 operator so the between operator from the name itself is very much Clear

2:18:16 let's let us say let us say we have two numbers 14 and 20.

2:18:22 so between is very simple and I have a third number

2:18:27 which is 15 I have let's say another number which is 22.

2:18:31 so between is very much simple if we just say oh let's say simple logic

2:18:37 is something like so 14 and this particular

2:18:46 number the second number which is 20.

2:18:48 and I have a third number which is 15.

2:18:51 so is 15 lying between 14 and 20.

2:18:55 is this true yes this is true the other number which

2:19:02 I have is 22 so the statement which will be something

2:19:08 like is 22 lying between 14 and 20 which is false

2:19:13 so this is not true so this is false this is

2:19:16 becoming as false so friends coming back to SQL Server management

2:19:21 Studio I'll just write here to help you explain the between

2:19:26 function so I'll just write here select star from details

2:19:34 where class so let's say I want to get the details

2:19:41 of all the students who are studying between the standard

2:19:45 fourth to standard six so I'll just write here between 4

2:19:51 and six so this particular query it will give the result

2:19:55 of all the details of the students who are studying in standard

2:20:00 4 in standard five and in standard six so it

2:20:03 will include the boundary level conditions which will be given so

2:20:06 the boundary level condition which we have provided here is four

2:20:10 and six so it will include four and six also and if

2:20:14 any of the inside range numbers are being satisfied so

2:20:18 it will give those particular values also so ideally we should

2:20:22 get four five and six whereas class results students so you

2:20:27 can just see here we are getting five and six why

2:20:30 aren't we getting 4 this is because there was no students

2:20:34 who was studying in class four so that is why we

2:20:37 aren't getting any student details from the class four so friends

2:20:42 this is all about the between function let us move back

2:20:49 to the next operator which is into our bucket you

2:20:53 can see here this is is null so friends I hope

2:20:58 the concept of null is quite clear to you all basically

2:21:01 meant if there is a cell where there is no value

2:21:07 which is present so that is called as a null so

2:21:13 friends let us say I'll insert two values here I'll give

2:21:23 them as null I'll execute this particular query this is

2:21:30 the primary thing which we discussed so I'll just change the name

2:21:35 that is causing an issue so I'll just execute this particular

2:21:39 query so you can see two rows inserted I will

2:21:42 do a select star from details so you can see both

2:21:46 of these rows have been inserted the operator which I was

2:21:49 talking about is is null so friends how does is null

2:21:53 and what do what does is null mean so null is

2:21:56 basically you can see there is no value present into the stream

2:21:59 ID for these particular students there's no value only so

2:22:03 this is termed as a null because if there is no

2:22:05 value present so it should be called something and that is

2:22:09 called as null let's say I want to get the details

2:22:11 of all these students is equal to null so how

2:22:17 should be the query be looking like so I'll just write

2:22:19 a select star from details where stream ID is null over

2:22:29 when I'll be executing this particular query you can just see

2:22:32 I'm getting two rows I'm getting all the rows in which

2:22:35 stream ID is equal to null I'm getting the desired result

2:22:39 now friends let us say I want to get the opposite

2:22:42 of this particular result the stream ID is not equal

2:22:45 to null so it should not be null there should be

2:22:48 a value which should be present into the stream ID column

2:22:51 so that is something like where stream ID is not null

2:22:55 I'll just execute this so you can see under your screen

2:23:00 I'm getting the details of all the students uh where stream

2:23:04 ID is not equal to null so difference this is how

2:23:07 the not null or is null function is walking let's move

2:23:11 to the next operator which is in now this is

2:23:16 a very interesting uh function or operator which is the in function

2:23:20 now why is this interesting so this is a very easy

2:23:24 way to write the or operator let us see let us

2:23:28 say I want to get the details of all these students

2:23:31 who study in class let's say class 1 to class 10.

2:23:37 so how should we write this particular query so

2:23:40 I'll just write here select star from details where so

2:23:45 I want to get the details of all the students

2:23:46 who are studying from into class 1 to class 10.

2:23:50 so we could just solve this particular problem using the or function

2:23:54 we'll just write it separately where class is equal to zero or class

2:24:00 is equal to 1 or class is equal to 2 so similarly we'll

2:24:06 be going to going on to right till class is equal to 10.

2:24:10 so this is a very long piece of code very you know not

2:24:14 a good practice to write such a long piece of code so to solve

2:24:18 this particular issue we have this in operators so the in operator is quite

2:24:23 simple so I'll just try to select star from details where class in so inside

2:24:30 this in we need to open the bracket I hope this order condition is quite

2:24:36 clear because any of these conditions should

2:24:39 satisfy so I want to get the details

2:24:42 of all the students who are either in class 0 either in class 1

2:24:46 either in class 2 either in class 4 either in class 10 so I just

2:24:50 want to get the details of all the students so any of the conditions

2:24:54 should be true we'll be getting the result of the true condition so we are

2:24:59 coming back to in condition so how this should this will work so inside

2:25:03 this in whatever we are writing that will act as the or operator above you

2:25:08 can just see so I'll just need to provide one two three four five

2:25:11 six seven eight nine and ten so this is so simple in just one line

2:25:17 of code will be getting all the details so you can see I'm getting

2:25:20 the details of all the students who are studying between Class 1 to class 10.

2:25:25 so this is how uh the in condition work it solves the purpose of not

2:25:30 applying the or condition again and again

2:25:32 and we're just writing the in condition once

2:25:34 and that is how we are solving the purpose let us move to the next operator

2:25:38 which is present here which is the distinct

2:25:42 now friends what is the distinct Operator Let

2:25:45 us move back to the Excel so the from the distinct word from the name

2:25:51 what is clear like what does distinct mean

2:25:54 so distinct means basically the unique things which

2:25:58 are present so let's say we have

2:26:00 this particular name or name of all the students

2:26:03 and I want to know how many distinct names students are presenting to my class

2:26:09 so how do uh how do we get to know our ask is something like

2:26:14 I want to remove the duplicates from this particular

2:26:16 column so how should we go about

2:26:17 this so first of all I would select this particular column I'll go to data

2:26:21 tab you can see this remove duplicates I'll select this so it is saying you know

2:26:27 throwing me a message that 13 duplicate

2:26:30 values found and removed because the entire column

2:26:33 as you should I should just select

2:26:35 this particular range I'll again go to data tab

2:26:37 remove duplicates and let the OK button so you can see it is showing me

2:26:41 a message that four duplicate values found

2:26:43 and removed and nine unique value remains so I've

2:26:47 got all the unique values which are present into the column which I had copied

2:26:52 earlier so I just wanted to get the unique values the value only one time so

2:26:57 they might be the case the same name

2:26:58 student will be present multiple times as you

2:27:02 can just see here we have Robert who is repeating multiple times into our data

2:27:08 set but when we remove the duplicates you can just see Robert is only present

2:27:14 one time so this is the use of the distinct so this is done using

2:27:19 the distinct function into the SQL the same

2:27:21 operation we just move the duplicates from the particular

2:27:24 column the same operation is done using the a distinct function into this SQL so

2:27:30 I'll just go back to my screen and the same thing I'll be doing here

2:27:33 I'll be writing the function so just right

2:27:36 here select serve from details and let's say

2:27:41 I want to get the distinct students name so I'll just write here instead of cell

2:27:46 star I'll I want to get the output of all the distinct student names so

2:27:51 I'll just write yes distinct of student

2:27:55 name that's it let us execute this particular query you can see I'm getting all

2:28:01 the student name the distinct student name so mind

2:28:05 you this robot and this particular Robert

2:28:07 had two different students because you can see

2:28:10 your extra is being added here so these are

2:28:13 not actually duplicates these are two different unique

2:28:17 things so you can see we are using the distinct function to get the unique

2:28:22 values from a particular column this is how we use the distinct function let us

2:28:27 move back to the next operator which is present here which is the average count

2:28:33 okay so what is average average can be

2:28:37 termed something like let's say I have values

2:28:41 into a particular column let's say this is

2:28:43 uh marks column and I have the students

2:28:49 so these are let's say the student name S1 S2 is 3 S4 S5 and let's

2:28:59 say they have got some marks the full marks of the paper was I'll just

2:29:06 insert any random value here full marks of the paper was 100 I would just insert

2:29:13 some values random values they need no

2:29:17 meaning to these values okay so just assume

2:29:20 this to be some dummy values which I've

2:29:22 gathered here just for explanation purpose what does

2:29:25 average mean so you can see I have five students I let's say I want

2:29:28 to get to know the average marks

2:29:31 of this particular class of the five students so

2:29:34 how do we get to calculate the average average is nothing but the sum

2:29:40 of the numbers and the number of entries which we are having so it is it can

2:29:45 be defined something like sum of entries

2:29:52 divided by number of entries that's it is

2:29:59 that is the definition of the average so you can just see here how many entries

2:30:07 are we having so let's say I want to calculate the average of the marks

2:30:12 column so first is this so we require two things the number one thing which we

2:30:17 require is the sum of the entries the next thing which we require is the number

2:30:26 of entries so the sum of the entries so first of all let us generate

2:30:34 the sum of all of these entries which are present here you can see I've got

2:30:47 this sum and the number of entries which is present here so you can just see

2:30:51 there are five entries one two three four

2:30:54 five five student marks are there so just right here as five and how do we

2:30:58 calculate the average according to the our formula

2:31:01 so the average is something like the sum of the entries divided by the number

2:31:10 of entries you can see the average marks is 70.4 so friends this is the average

2:31:17 let us move to the next operator don't worry I'll can be displaying this how

2:31:22 do we use this into the uh SQL Server management Studio practically let's let us

2:31:29 get back a summary let us understand

2:31:30 all of these different operators how do they

2:31:33 operate the count function let us see

2:31:36 this what does count mean into the Excel count

2:31:39 is from the name itself is quite clear the number of entries which are present

2:31:44 so number of entries which is present here is five so the count will be 5.

2:31:54 the next thing which is present next operator which we

2:31:59 are talking about is Max Min and sum so I just

2:32:01 write here Max Min and sum the maximum value which is

2:32:07 present among all of these entries so we want to get

2:32:10 that result so I'll just write here Max function the same

2:32:13 function is present into the Excel as well so I'll

2:32:16 just select the entire range I'll enter the enter the button

2:32:19 so you can just just see the maximum marks is 84.

2:32:22 similarly there is a Min function which is present here the mean of marks I'll

2:32:28 just select the range you can see

2:32:30 the minimum marks which I'm getting here is 62.

2:32:33 the last operator which is present here is the sum operator so

2:32:37 how does the sum operator work so I'll just get the sum

2:32:40 I'll select the range for which I want to get the sum

2:32:43 and lit enter you can see I am getting the sum as 352.

2:32:49 now friends let us do the same thing into the SQL let's make a new

2:32:54 table and we'll do the same thing I'll just copy part of the code

2:33:00 so that I don't have to rewrite from the very beginning so let us

2:33:05 rename this as marks so I have the student name let us see okay five

2:33:29 rows affected great so I'll just do a select from marks the first function

2:33:38 here is I'll just show you guys which is the average let us say I

2:33:46 want to get the average Mark so the function which is the average EBT

2:33:52 that's all I'll just execute this particular

2:33:55 query the answer which I'm getting is 70.

2:33:58 we got it here in terms of decimal places we can get it

2:34:03 there also uh so we are getting here the answer is 70 so

2:34:08 the answer is matching exactly the next one is the count uh operator

2:34:15 as you can see your next one is the count it will count the number

2:34:19 of entries which is present so instead of average I'll write here

2:34:22 as count you can see I'm getting as 5 here also we have got

2:34:26 the count as five the next one is the max the maximum marks

2:34:32 which is present into the column you can see the maximum marks is 84.

2:34:38 same is present here the minimum marks is which is

2:34:44 present I'll just select this the minimum marks is 62.

2:34:52 the minimum marks is 62 as you can see the last but not the least

2:34:58 is the sum oh sum of marks it should give the output as 352

2:35:04 as we can see into the Excel so you could just see we are

2:35:08 getting the answer as 352 here so friends this was all about the SQL

2:35:13 operators let us move to the next concept into the SQL B many more

2:35:19 operators also but these are more than enough to solve any complex level problem

2:35:23 into the SQL let us move to the next part which is

2:35:27 on to the wild card so what is exactly wild card I'll just show you guys

2:35:32 and this is also very interesting thing I'll be using this details table only

2:35:36 which we have created I'll execute this let's say let's say I want to get

2:35:43 the details of all these students whose name start with Rob ROP I want

2:35:51 to get the details of all the students whose name starts with r OB so

2:35:55 how do we get about this so this is solved using the wild card

2:35:59 so I'll just write this select star

2:36:01 from details I'll just write here where student

2:36:09 name and I'll write here like so student name should be like so whatever

2:36:16 condition we have present we need to mention this year so student name should be

2:36:21 starting with the word ROM so it should be something like Rob and anything

2:36:29 which comes after the word Rob I am not concerned anything could be there

2:36:33 but I just want to get the details of the name of the students

2:36:37 whose name starts with Rob I'm not concerned after Rob anything can come up I'm

2:36:43 not concerned with that so so whatever I told to put this part

2:36:48 into the code I need to replace this with a percentage sign and that will tell

2:36:55 the code that the word should start with something like Rob and then after

2:37:01 that anything any number of characters comes up I am not concerned with it I'm

2:37:07 just concerned with the name should start with Rob so this was the problem

2:37:11 we started with we started with that I want to get the output of all

2:37:15 the students whose name start with Rob so this is how I translated

2:37:19 the language the problem into the code

2:37:21 let us execute this particular query you can see I'm getting the details of all

2:37:27 the students who are actually starting with Rob

2:37:30 even if the student names are different you could just see the last entry

2:37:34 it it is it is having uh extra e into the name of the student

2:37:40 but we are getting the desired result now let's say I want to get

2:37:44 the details of all the students whose name does not start with Rob how

2:37:50 do we go about it it is very simple just we need to add here

2:37:55 not like and we just need to execute this particular query you can see

2:38:00 I'm getting the details of all the students whose name does not start with Rob

2:38:04 none of the student which is present here the name is starting with Rob so

2:38:09 this is how we are solving that particular

2:38:10 issue now coming back to this particular

2:38:13 wild card so this was something that a string is starting with a certain

2:38:19 characters there might be a case this the string should end with a certain

2:38:24 characters so if I go back to this select star from details so let's

2:38:31 say I want to get all the details of the students whose name ends

2:38:39 with ID so I want to get the details of all the students whose

2:38:44 name is ending with ID so how do I translate this into the code how

2:38:48 do I translate this particular problem in terms of the code so if

2:38:52 this should look something like so the name should I end with i and D

2:38:58 so this should be the ending part what should be the starting part starting

2:39:02 part would be anything I'm not concerned with it I'm not concerned how the name

2:39:07 is starting or how many characters it is having so it will be replaced

2:39:11 with a percentage sign but the last two characters or the now or the you

2:39:17 know the name should end with i and D that is only I'm concerned

2:39:21 with so this is how I'll be writing this in terms of the code

2:39:26 I'll execute this particular but command you can see I'm meeting a student name

2:39:30 is David who is coming up and you can just see the name is actually

2:39:36 ending with i and T so this is how we are matching the patterns

2:39:40 it you can just term this wild card as matching patterns in the string think

2:39:45 one more interesting part is we just saw that a swing good start

2:39:50 with anything we are able to find it a string can end with anything we

2:39:54 are able to find it what if between the springs I want to know

2:40:00 that if the string between the strings

2:40:02 if these characters are present or not how

2:40:04 do we translate this into the code let us say I want to get

2:40:08 the details of all these students name

2:40:10 contains ens consecutively so irrespective of whatever

2:40:14 their name is their name should contain

2:40:16 ensn this should be the pattern exactly so

2:40:22 how should we go about writing this particular

2:40:25 thing so first thing is the pattern

2:40:28 is e n s so what should be the ending part so ending part

2:40:35 could be anything correct I'm just concerned that the name should contain e s

2:40:42 in consecutive way so this is a percentage sign name can end in anything

2:40:50 so that is why percentage sign similarly the name can start with anything so I

2:40:58 just mentioned the percentage sign here

2:41:01 so how does this translate this translate in something like the name can start

2:41:07 with anything between the words ens should come

2:41:11 in consecutive way and the name can end in anything so this is how I

2:41:17 translated the the code you the the problem in terms of the SQL code let

2:41:23 us execute this particular query let's see if we are getting any result now

2:41:28 one more thing we are only concerned that into the name of the student e

2:41:34 s should be present in consecutive way into this particular fashion so the name

2:41:39 also it can start with ens or the name also it can end with e

2:41:45 n s so I don't think so they could be something like es

2:41:50 and some random alphabets so you can just consider this to be a name

2:41:56 of the student ideally this is not a name but I just wrote here

2:41:59 to explain you something so this particular condition

2:42:03 will also be satisfied here because the name should can start with anything or e

2:42:09 also this particular condition also satisfies here

2:42:14 because the name ends with ESO the name can end with ens and this particular

2:42:21 condition also satisfied because between the in in this string we can see ens

2:42:28 is present here so all of these three conditions will come up into the output

2:42:32 of this particular result so I'll just

2:42:34 execute this particular query I hope this is

2:42:37 pretty much clear so you can just see here into all of these names

2:42:41 you can just see in Jessica e and s is present between the between

2:42:48 the string it is not present into the extreme ends likewise here you

2:42:52 can see e s is present into the end part of the string

2:42:57 the point which I was discussing before

2:43:00 so we'll be getting this particular condition so

2:43:03 this is how the Wild Card actually it works so you can get any

2:43:08 pattern matching so if you want to match any pattern let's say something starts

2:43:13 with a particular word some you want to grab all the details just use

2:43:17 this wild card function here and you will

2:43:20 be sorted now friends moving to the another

2:43:24 thing which is let's say I want I have 100 rows into my data

2:43:31 set but I am just concerned with getting the top three entries from my data

2:43:38 set so you can see from the marks table which we had created I'll

2:43:48 just replace this with star so I'll just do a select star from marks you

2:43:54 can see here I'm getting the select star from marks let's say from this five

2:43:59 student marks I just want to filter out the marks of this the top

2:44:03 two scorer marks how do we go about this so one way could be

2:44:10 you know get the first marks and get the second marks and there is

2:44:17 this Union function we'll be learning this later

2:44:19 but Union function in summary if I

2:44:22 just want to summarize this is you can just join two results in a vertical

2:44:26 way so if the number of columns are same the design is same

2:44:29 the pattern is same like in the First Column we should have student name

2:44:32 into the second column we have marked so

2:44:34 we can join them vertically and this could

2:44:36 solve our problem but let's say here we are just uh want to get

2:44:41 the top two marks what if we want to get the top 100 marks

2:44:46 let's say we have 1000 set of students and I want to get top

2:44:50 100 Mark students so that would be a very uh not a good process

2:44:54 so to replace this we sort our results in some way so in I think

2:45:01 in my SQL we have this limit function but there is a limitation

2:45:05 in MySQL server limit does not work so that's why we use the top function

2:45:10 it works in the same way just the syntax it has changed friends

2:45:15 from this particular Mark stable you can see I want to get the top three marks

2:45:21 or top two marks whichever the student details and their marks which have been

2:45:25 scored the top three score from this particular

2:45:28 class so we will get this particular

2:45:31 information we'll be sorting this particular information

2:45:33 we'll be getting this particular information using

2:45:35 the top function this is this limit function

2:45:38 which is similarly it works in the MySQL

2:45:41 let's see what is the syntax of getting the top three score marks so

2:45:45 I'll just write here select top three so let's say I want to get

2:45:49 the top three scorers so I'll just write a top three star from marks

2:45:57 so I'll just execute this particular query let us see what is the result so

2:46:03 you can see the result which I am getting is quite wrong from the result

2:46:08 only we can just see because the top marks is only 84 so

2:46:12 we should have got in into the output we should have got 84 77

2:46:16 and then 65 but the result which we are getting is 64 65 and 62.

2:46:23 so are are we doing the things rightly the answer

2:46:27 is no so here comes the another function which is

2:46:31 the order by Clause so let's say what will

2:46:35 the output of this particular uh you know the query so

2:46:40 what will be the output so the output

2:46:42 of this particular query will be something like so let's say

2:46:45 the data is present here into the Excel so we

2:46:50 are doing we are telling into our code that select top

2:46:54 three star from Mark so it will do nothing it

2:46:57 will just select the top three rows and that is

2:47:01 exactly the output which you we are getting so you

2:47:03 can just verify 64 65 and 62 that is exactly

2:47:08 what we are getting into our output so this should

2:47:13 not exactly how the queries should work the query should

2:47:16 work something like first of all from this entire data

2:47:20 set the the data set should be arranged in terms

2:47:24 of marks so I'll just write this sort

2:47:29 A to Z or I would just go here dot launches

2:47:38 to smallest so you can just see here first

2:47:40 of all what should be have been done is data set

2:47:44 from here it should be transformed to this where

2:47:49 the data set is aligned in terms of a descending order

2:47:55 of the mark so the highest marks should be

2:47:57 into the topmost row after this has been done the the another

2:48:02 transformation should be done is we want to get

2:48:05 the top three marks so the top three entries will

2:48:08 be selected and pasted so you are getting the top

2:48:12 three increase and or the top three marks so all

2:48:15 of these Transformations should be happening into our data set

2:48:19 how do I formulate this into the code so friends

2:48:24 right now what is happening is totally wrong so what

2:48:28 I help you understand into the Excel sheet was like

2:48:32 the first of all our data set is like

2:48:33 this somehow we should get transformed into this and then

2:48:37 and only after this has been transformed it is just

2:48:40 a matter of fact for fetching the first three rows like

2:48:44 how it is doing right now is it is just

2:48:47 fetching these first three rows and it is pasting so

2:48:50 before copying the first three rows and pasting it

2:48:53 into the output this operation should happen in between so we'll

2:48:58 need to write some part of the code so

2:49:00 that this operation happens and then it is just a matter

2:49:03 of fact that the first the this query will run

2:49:06 and will be getting our desired result so the additional

2:49:10 part of the code which we should write is

2:49:12 something like we have a data set ready we need

2:49:16 to first of all we will just see what I

2:49:19 did is I I sorted the the data set in terms

2:49:23 of the marks in the descending order so what

2:49:26 we should do here is I'll add another entry here

2:49:29 which is something like order by so into what column

2:49:33 model what column basis do you want me to order

2:49:36 by I want to order by I want to the basis

2:49:39 of the score column now friends let us execute

2:49:43 this particular query let's see what is the output which

2:49:45 we are getting so you can see the output which I

2:49:47 am getting is something like 64 60 60 to 64 and 65 let us do one thing I'll copy

2:49:57 this and I would paste this here so this is

2:50:00 the output which I'm getting currently from my code now if

2:50:04 you would just see this so what I did is

2:50:09 I I'll just copy this so this is my data

2:50:12 set don't get confused from the different outputs which I'm

2:50:15 having right now just follow with me into this particular

2:50:18 video so this is the data set which I am

2:50:20 having right now let us say I am just doing

2:50:24 this into the ascending order so I'll just select

2:50:29 this I will put this [Music] you can see I have

2:50:37 sorted this in terms of ascending order 6460 62 64

2:50:42 65 7784 so this is sorted in ascending order what

2:50:46 if I want to get the top three results

2:50:49 from here so I'll just copy this and paste this here

2:50:52 so do you find any similarities between both

2:50:55 of these results yes you can find the similarity so what

2:50:59 is happening right now is it is getting in sorted

2:51:03 in terms of ascending order on of the score column

2:51:07 we need to do in the opposite way we need

2:51:11 to sort this in terms of descending order so what

2:51:13 is the additional thing we need to write here so

2:51:15 the additional thing which we need to write here is

2:51:18 d e s c and that's all it will

2:51:20 be sorted in terms of descending order so the output

2:51:24 the the internal operation what will happen will be something

2:51:27 like we have our dump here we have our table

2:51:30 here this will be sorted in terms of you know

2:51:34 descending order likewise and the output final output which will

2:51:38 be getting is kind of this so let us execute

2:51:41 our query finally and let us see if we are

2:51:43 getting the correct result or not so you can see

2:51:45 we are getting the correct result the we are reading

2:51:48 the the result in which the score has been sorted

2:51:51 in terms of the descending order so friends this is

2:51:54 how we have solved this particular problem where we needed

2:51:58 to sort the results in terms of descending orderly so

2:52:01 I hope this particular sorting thing is quite clear now

2:52:04 let us move to the next section which is present

2:52:07 here so I hope the wild card and the Sorting

2:52:10 part is now clear wildcard is clear the Sorting is

2:52:12 clear limit and top function which we have seen next

2:52:16 is the important part the most important part don't miss

2:52:20 this particular part because here I'll be discussing all

2:52:23 the functions present into the sequel which is necessary for you

2:52:27 to solve any complex level of problem I've discussed all

2:52:32 these functions which are present into the SQL just go

2:52:36 through this particular particular part of this particular video don't

2:52:40 skip any of the part because you might be losing

2:52:44 on information and if you're losing your information you won't

2:52:47 be able to solve problems because this function helps us

2:52:51 to solve a particular problem much more easier way rather

2:52:55 writing a particular part of the core so if we

2:52:58 know a function we can just do it very quickly

2:53:00 so I'm starting this particular series of function in SQL

2:53:04 first we'll I'll be discussing the string functions so

2:53:08 the very first function which I am having here is

2:53:12 the care underscore length so what does this function do

2:53:15 so friends let us say into my SQL Server I'll just

2:53:19 go here or into the Excel I'll just go here

2:53:22 and I want to know the length of or the number

2:53:26 of characters which is present now or the number

2:53:30 of characters from which the name of all the students

2:53:32 are made up of so let's say James is

2:53:34 there so how many characters are present into the name

2:53:37 of James so I can just see j a m

2:53:40 e s so there are total more five characters which

2:53:43 are present into the name of James similarly Robert how

2:53:47 many characters are present so you can see here r-o-b-e-r-t

2:53:51 so one two three four five six so six characters

2:53:55 are present so this is solved using the character underscore

2:54:00 length function into the SQL let us see how

2:54:04 do we do this so for this I'll be using

2:54:07 the details table earlier which we have created let us

2:54:12 go to the select star from details let us execute

2:54:14 this so I have got the student underscore name column

2:54:21 here I'll just write here student underscore name select student

2:54:29 underscore name from details so you can see I'm getting

2:54:33 all the students name let us say to the next

2:54:36 column I want to get the length of the students

2:54:41 name similarly to what I was doing into the Excel

2:54:43 so in Excel also we have this l e n

2:54:47 function through which I can get the length of the string

2:54:52 which is present here so a similar thing is solved

2:54:55 using the character underscore length function is execute this particular

2:54:59 query okay so it is saying that care underscore

2:55:03 length is not a recognized built in function so what

2:55:06 does this mean so I've just done this intentionally

2:55:10 and this is because you might be seeing that let's

2:55:13 say there are various other dbms which is present right

2:55:16 now MySQL postgresql Oracle I'm using ssms what happens is

2:55:22 this is the point which I brought out earlier

2:55:24 that the logic would be the same but the syntax

2:55:28 or the functions which is present into all of these different

2:55:31 dbms would differ right now you can see this car underscore

2:55:35 length might work in MySQL let's see but it's it

2:55:39 is not working right now in the SSM so there

2:55:43 is a workaround for this there will be a different

2:55:45 function which will be doing the same thing but here

2:55:48 is the catch so the the function the thing which

2:55:52 we are doing is correct the the logic which we

2:55:55 are applying is correct but that using the correct function

2:55:57 which should be applied here and complies by the rule

2:56:00 of ssms so what is the function the function

2:56:03 here which satisfies into this SMS to get the length

2:56:08 of the character so it is is it length let

2:56:11 us just check so if length works or not I'll just

2:56:15 remove these characters I'll just execute this particular code

2:56:18 you can see length is also not a recognized built

2:56:22 in function name so this is not also working so

2:56:25 what works what actually works in ssms is len that's all

2:56:30 that's all work so I'll just execute this particular command

2:56:33 so you can just see uh that we are getting

2:56:36 the student names and the number of characters which are

2:56:39 present into all of these different name one more thing

2:56:43 into the output you can just see this particular column

2:56:45 it is named as student underscore name while this particular

2:56:49 column it has no column name so can we give

2:56:52 the column name in SQL do we have that particular

2:56:55 provision so definitely yes we can give the column

2:56:58 name and that can be given by it's very simple

2:57:01 we just need to write here as and after

2:57:05 as you can just mention the column name so it will

2:57:08 be length I'll just let's say I want to give

2:57:10 length of name so the column names which you are

2:57:16 giving this should not be any space between the column

2:57:19 name so if let's say I'll just remove this underscore

2:57:22 I'll put a you know a space it'll throw me

2:57:27 a error it will telling me a syntax error which

2:57:30 is present so instead of the space replace those spaces

2:57:33 with underscore and you'll be able to solve your problem

2:57:36 I'll execute this command and you can see the column

2:57:39 name has changed from no column name to length underscore

2:57:42 name so this is how we have solved this particular

2:57:44 problem of getting the student name so getting the student

2:57:48 character link so friends the first two functions is quite

2:57:53 clear I hope so both of these does the same

2:57:56 thing it's just that the character length it will provide

2:58:00 the the the number of characters have oil in terms

2:58:04 of the length into the output you will be getting

2:58:06 the number of bytes which is present into the character

2:58:10 coming to the third function which is the character

2:58:12 index now basically what does this character index function it

2:58:18 gives into the output so friends you can just see

2:58:21 here uh we have all of these different students name

2:58:25 which is present I'll use a different example I'll use

2:58:29 my name for displaying this particular function so I'll just

2:58:33 write here select and what's the what's the function name

2:58:39 it is character index so you can just see I'm

2:58:45 getting a help from SSM is that okay there is

2:58:49 a function which is present as car index do you

2:58:51 want to use this yes I want to use

2:58:53 this so generally we don't remember functions I mean if we

2:58:57 are using it very vigorously so generally I mean daily

2:59:01 if you are using it so we'll be remembering all

2:59:03 of these different functions so but in let's say you

2:59:07 are not remembering this particular function so even if you

2:59:10 type few characters of that particular function ssms will give

2:59:13 you uh the option to select from the drop down

2:59:16 you can just see I have just got the particular

2:59:19 option so Capital index so I'll just write here

2:59:23 into a string I'll write my name okay and what

2:59:29 does this particular function it do don't so you'll be telling

2:59:33 me don't write your name just explain me the function

2:59:36 characteristics so character index basically let's say I want

2:59:40 to know what is the index of this particular row

2:59:45 like which is the character index onto what is the index

2:59:49 on which this particular o is present into this particular

2:59:53 string by index I mean let's say this is

2:59:58 the complete string which I'm having currently so this particular

3:00:03 a the index of this a is one index

3:00:07 of s is equal to 2 H is equal to 3 likewise U 4 T is 5 O is equal

3:00:16 to 6 s is equal to 7 and H is equal to 8 so this is meant by the uh

3:00:22 by the index so let us say U t o s h so this is my name so the index

3:00:33 would be something like let us assume that the complete

3:00:36 index the complete string is of my name so the index

3:00:41 would be something like a would be one two

3:00:45 three four five six seven eight so this will be

3:00:48 the index so let us say I want to know

3:00:50 what is the index of this O So under what index

3:00:55 uh o is there into this particular string so it

3:00:59 is very not simple and this is the output which

3:01:01 we receive through this character index so I want

3:01:04 to know the index of this particular o so I'll just

3:01:10 mention in between codes so let us execute this particular

3:01:13 query what do you think what should be output

3:01:15 of this particular function you can see it is giving

3:01:17 me a six so let us see if o was present at 6 or not so yes o was present

3:01:23 in six so this is exactly the same result which we

3:01:28 got so this is the use this is how do

3:01:30 we use the character index function now we will say

3:01:34 me ask those that let us say your name is

3:01:36 ashutosh more okay to avoid confusion write in caps correct

3:01:49 and it will be like k u m a r so the character would be 9 10 11 12 13.

3:02:02 correct and similar thing I'll just write this here so I'll just write my last

3:02:09 name also okay and let's say I want to get the now the character

3:02:19 index of this m so instead of oh I want to on I now want

3:02:23 to get the character index of this particular M uh character so I've replaced o

3:02:28 with M let us execute this particular query what do you think what should be

3:02:32 there is the result let us go back to the Excel so m is equal

3:02:36 to 11 so we ideally we should be getting 11 Let's see we are getting

3:02:40 11 or not so I'll just execute

3:02:41 this particular command you can see I'm getting 12.

3:02:44 so is our logic somewhere wrong or there any logic mistake

3:02:49 in that definitely not and why because these you can see the space which

3:02:55 is present here this space is also counted as a particular character

3:03:00 and this has a character index actually so that is why you can just

3:03:06 see H was equal to 8 so this space becomes nine K

3:03:11 becomes 10 U becomes 11 and the M becomes 12 so the space

3:03:17 also has a index number attached to it so ideally between this they

3:03:24 should be a row that has a space and this should be nine

3:03:34 and while all of these this would be changed respectively now you

3:03:45 can see m is equal to 12 and that is exactly the result

3:03:48 which we got so friends this was all about the character index function

3:03:54 this is very interesting function while I'll just show you I'll just open

3:03:58 my Excel I'll open a new tab let us say I have

3:04:03 a column where I have a student first name into the next column

3:04:13 let's say I have the students second name and to the third column

3:04:19 I have the students last name so friends let's say the first name

3:04:27 I'll just put any dummy characters here the second name and the last

3:04:34 name so let us assume there is an entry like this and we'll

3:04:39 just take one more entry first name F2 second name is

3:04:43 to the last name is L2 so friends let's say I want to get

3:04:49 the student name such as F1 S1 and L1 into the column

3:04:57 number is d now I'll just take some real name so that it

3:05:02 does not confuse you guys so I'll just type here from um okay

3:05:11 so and what is output I want output I want is something like

3:05:17 the full name of the student theme to the column D I

3:05:23 have the full name of the student so this is the output which

3:05:26 I want you can just imagine right now I'm having just three columns

3:05:31 in which values are present but in two real scenarios this this will

3:05:35 not be as simple as it is looking out here we'll be having

3:05:39 multiple columns in which values belief in let's say it will be 99

3:05:43 columns 100 columns let's say you're solving a problem and you need

3:05:46 to join all of those 99 or 100 columns so how tedious it is

3:05:51 how manually impossible it is to do if you are going to just

3:05:55 pick each and every cell value and put it into the cell

3:05:59 the last cell so friends this is solved using the concat function

3:06:03 you can just see the concat function is also available into the Excel

3:06:08 as well so it's quite simple you need to do a concat

3:06:14 and just select this the cells for on which you need to concrete

3:06:20 that will be generated starting it is concatenate in Excel you can see

3:06:27 all of these values are now concatenated

3:06:30 all of these different first name second

3:06:32 name and the last name are concatenated in other terms they are

3:06:36 joined uh in sequentially and then they are presented into the result section

3:06:41 so you can just see and you can just question after I can

3:06:45 find a space in between the characters uh so how do I give

3:06:49 this space so giving space is quite simple so let's say A4 so

3:06:54 what is A4 in A4 we have the first name so after first

3:06:57 name I want to give space so to give space I need

3:07:00 to open the codes and in between the codes I'll be providing a space

3:07:06 similarly after B4 I want to give a space so I'll just

3:07:10 put another character and the character would be r space so it you

3:07:16 can just think of it's something like you are joining you're joining one

3:07:19 character to the other character so space is also a string character you're

3:07:24 just joining this the space character with the previous word or the last

3:07:28 word I'll hit enter you can just see the space version entry

3:07:32 let's say I wanted to give comma instead of space so here uh

3:07:37 in space I can just give comma and you can see the name

3:07:44 has been generated because this is how we are solving this particular

3:07:48 problem and the same problem we could see into the SQL Server management

3:07:53 studio also so I'll just take I'll just show you guys how

3:07:58 this concat function works so I'll just write it on select concat and here

3:08:06 I'll be writing all the all the characters which I want to point

3:08:12 get so just write it as it is let us execute this connect

3:08:30 this out and you can see into the output this the result has

3:08:34 been deleted but uh I want space between all of these words so

3:08:39 to give this space I'll do the same thing what I did

3:08:42 into the Excel I'll provide string codes and in between the stream codes

3:08:47 I'll be providing space that's it let us execute the query once more

3:08:53 and you can see the space has been provided let us say I

3:08:56 want to give former instead of space so we'll just do this I'll

3:09:03 execute this command you can see the comma has been provided instead

3:09:08 of this space so friends this is how the oncat function is working

3:09:11 now these are I've just provided names here directly let's say these values

3:09:17 are present into the column so in that case you just need

3:09:21 to provide the column names I'll just show you guys an example like

3:09:25 this where available another difference I'll

3:09:40 execute this query okay one row effective

3:09:46 it is saying I'll do a select star ROM names that's it let

3:09:57 us execute bigquery you can see I'm getting we select start from names

3:10:02 I am getting all the results the desired result now into the fourth

3:10:06 column let's say I want to generate a full name and in that I

3:10:10 want to get the full name of the student so I'll use

3:10:13 the concrete function for that and concat I want to convert first

3:10:19 name so here you need to provide the column name which you

3:10:23 want to concrete so first name that can name and last name

3:10:30 you are concatenating let us execute this a new column will be generated

3:10:35 for this as you can see a new column has been generated let

3:10:38 us rename this column so to rename the column you can just write

3:10:42 a full name or you can add as full name you can see

3:10:48 I wanted the space between all of these names so I'll just skip normal

3:10:53 space and it does as well that's it I think this will work

3:11:00 and this one server so you can see here I'm getting a new

3:11:05 column as full name I added the new column I'm generating the name

3:11:09 of the student so I hope the concat function is quite clear

3:11:13 it is a very important function when we deal with the string function

3:11:17 into the SQL so to practice this a lot let's move to the next

3:11:21 function the left and right function so friends what is the left

3:11:26 and right function let us go back to the Excel first of all

3:11:29 understand we'll understand this in Excel and then we'll move to the SQL

3:11:35 Server management studio now what is the left function from the name

3:11:39 itself it is quite clear that it sounds something as if we'll be

3:11:43 doing something from the left side and from the right function it similarly

3:11:49 it sounds something like we'll be dealing something from the right side so

3:11:53 friends let's say into this particular name I want to get the first

3:11:59 two characters the first two characters from this particular name so how do

3:12:03 I go about doing this we can solve this problem with the help

3:12:08 of the left function the left function we'll just do it choose

3:12:14 the function and write the number of characters which you want to choose

3:12:19 from the left hand side so the number of vectors which I want

3:12:23 to choose from the left hand side let's say are the first two

3:12:26 vectors the first two characters of the name so I'll just hit

3:12:29 enter and you can see the first two characters have been chosen similarly

3:12:34 let's say I want to grab the last character of the this particular

3:12:39 name so to do this I'll just write here write and I'll choose

3:12:44 the text from which I want to grab the last character

3:12:46 and to grab the last sector that means that I just want to grab

3:12:51 the the last character that is the one character from the right hand

3:12:56 side and I'll hit enter and you can see I've I have grabbed

3:13:00 the last cutter which is r a which is M into the first

3:13:05 name so friends this is how this is actually the use of the left

3:13:10 and right function let us move back to the ssmsl do the similar

3:13:14 thing into the ssms as well so I have created a table

3:13:18 name as names I just get that into my output and I'll do

3:13:26 the same thing I'll execute the same thing here as well and you'll

3:13:31 get an idea how all of these are working so I'll do

3:13:35 a select and let's say I want to grab the first two characters

3:13:39 from the first name so from the first name column I want

3:13:45 to grab the first Vector so I'll just do a left function the column

3:13:50 in which the first name character is present and the number of characters

3:13:54 which I want to grab from the left hand side that is 2.

3:13:59 and from name so let's see if this works or not let us

3:14:09 execute this particular query and you can see it works so so we can

3:14:16 just rename this column as first to characters and similarly let us grab

3:14:26 the last character from the name using the write function here so I'll just

3:14:33 write here write and first name comma with one because I want to grab

3:14:42 the last character I'll just execute this particular command let us see what

3:14:47 is the output which we are getting you can see I'm getting the right

3:14:50 output and this is the last character so these are some of the good

3:14:56 coding practices which we should follow wherever we are making a new column

3:15:00 better give a name to it so that when we are using it

3:15:03 later we can just use the column name so it is it is

3:15:07 good to follow good coding practices while you are writing the codes I'll just

3:15:12 execute this particular query and you can see we are getting the desired

3:15:15 result let us move to the next function here which is the the place

3:15:20 function so friends let us say into the name here itself I want

3:15:27 to replace a certain character with a particular

3:15:31 some set of different characters itself

3:15:33 let us say into this particular name I want to replace um

3:15:38 with mu or a matter of fact let us say I want to do

3:15:42 this so how do I do this I do I'll do this using

3:15:45 the replace function so first of all I'll just show this into the Excel so

3:15:52 first of all I'll select the old text and the starting number from which

3:15:57 I want to change the character so I want to replace u m

3:16:02 with mu so I need to I need to say to my code

3:16:07 that this um is present at this particular location so I want to grab

3:16:13 that location so a starts with Once what is the character index of K

3:16:18 the character index of K is 1 similarly the character index of U

3:16:23 is two so I want to I'll write here 2 because start

3:16:27 from the two width character and then

3:16:30 it is saying the number of characters which

3:16:33 you want to replace so I just want to replace after 2 I

3:16:36 want to replace two characters and the new text with which you want

3:16:41 to replace so the new text with which I want to replace U

3:16:45 and this m u so I'll just write this I'll just mention this here I'll

3:16:49 hit enter and you can see into the result I have got the desired

3:16:54 result you can see the MU which was present here it has been

3:16:59 replaced with sorry the u m which was present here that has been

3:17:06 replaced with mu so friends of all this we have achieved using the replace

3:17:13 functional please don't get confused that we can just replace the same number

3:17:17 of characters so let's say in um there are two characters which I

3:17:22 had to replace so uh these two characters are replaced by another two

3:17:26 set of characters which is M it is not necessary you can just replace

3:17:31 with as many characters as we want to like I'll just put a replace

3:17:36 function the old text starting number is to the number of characters let's

3:17:42 say I want to replace this blue on them so I'll just say

3:17:45 two in the new text with which I want to replace so I'll just

3:17:48 can put any number of characters here and I'll hit enter and you

3:17:52 can see that u n is being replaced with such a large character so

3:17:57 the Size Doesn't Matter here you can just replace as many as character you

3:18:03 want to that is the thunder so you can just see I've replaced you

3:18:09 and with the this large set of strings so friends I hope this is

3:18:14 pretty much Clear let's move to the SQL Server management studio and let's

3:18:17 perform the same thing there is a small difference into the syntax

3:18:21 of the function of the place for on how we are writing it in Excel

3:18:25 and how we are performing the same thing to the sequel so in SQL

3:18:28 you just need to provide the column name in which the values are

3:18:31 present and into the next entry you will need to provide the string

3:18:35 which you want to replace so uh I want to replace the string which

3:18:40 is u m the string with which you want to replace this particular

3:18:45 viewer character so I want to replace it with m u that's it I'll

3:18:52 execute this command and you can see I'll just present the old string

3:19:00 also this so those string was second name let us execute this particular command

3:19:06 and you can see the the older version was k-u-m-a-r and we have

3:19:11 replaced u m with m u with the help of the replace function uh

3:19:16 the syntax you can see right here onto your screen and this has been

3:19:20 served with the help of the replacement letters uh let's see if we can

3:19:26 replace the same number of characters or we can replace as many as characters

3:19:30 which we want to replace it with so I'll execute this command as well

3:19:35 and you can see here I have replaced you and with this particular

3:19:41 long string this is all about the replace function let's move to the next

3:19:45 function which is present here I'm just going slow I'm just covering all

3:19:49 the different concepts so if you're feeling like I'm going to Too Much

3:19:52 depth you can just watch this at a speed of 1.5 x

3:19:56 but the intention is to cover these Concepts into a lot of more details so

3:20:01 that you do not face any problem into the interviews you're just learning

3:20:06 all these Concepts on the go you don't need to watch or you don't

3:20:10 need to revisit the concepts again and again one time you one time

3:20:14 you've seen you are done and you could just start solving the problems which

3:20:18 I've solved into my hacker rank problem playlist or delete code problem playlist

3:20:22 you can also start solving the interview

3:20:25 questions which I generally post as videos

3:20:28 so you can just go and start solving all those problems after you

3:20:32 have completed this particular video so friends

3:20:35 let's move to the next function which

3:20:36 is the the words function the reverse functions are and just do

3:20:40 with the last name this time so I'll just write here every verse and I'll

3:20:46 just select 3D last name ROM names let's see let us execute this particular

3:20:56 code let us see if we are getting any output or not so

3:21:02 yes we have got an output and you can see the string has

3:21:06 been reversed so this has been achieved through the reverse function now you can

3:21:11 question me there are so many functions do we really use this into the real

3:21:16 case scenario when we are solving the real case problem so the answer

3:21:20 is yes we use this action simply and this depends on the type

3:21:24 of the problem which we are solving substring or substrate so what is

3:21:28 the use of the substring function let's say from a particular uh you know

3:21:33 the string you want to grab a certain set of characters from the string

3:21:37 it can be either from the beginning or from the ending part

3:21:41 or from the middle of the string you want to grab a certain set

3:21:44 of characters so this particular thing is

3:21:47 achieved with the help of the substrate

3:21:48 function so we just saw using the left function using the right function we

3:21:53 were grabbing the the first set of characters from the left hand side

3:21:57 and using the right function we were grabbing the last set of letters

3:22:02 from the right hand side but using the substring function this is a kind

3:22:06 of versatile thing you can just grab any set of characters in between

3:22:10 the string also or from the left hand side right hand side as well

3:22:13 so let us see the syntax how is this achieved so I'll just

3:22:17 write here select sub string let us give the second name column and for matter

3:22:34 of fact let us assume that I want to grab the first three

3:22:36 characters so I'll just write here the first like from which character index

3:22:42 do you want to grab the character so I want to grab the characters

3:22:44 from the very first index so I'll just just write here one

3:22:47 and the number of characters which you want to grab so let's say I want

3:22:51 to grab three characters that's it and I'll just rename this as first

3:22:59 three characters from names that's it let

3:23:08 the column let us execute this particular

3:23:12 query you can see I did the same thing using the left function

3:23:17 as well so I'll just use the left function left of second name from which

3:23:30 focuses you'll be PDF function I don't think we give the starting characters

3:23:39 because it is believed that left function will start from the left itself so

3:23:44 you can just see the left function as well as the substring function

3:23:47 it is giving this same set of results they're trying to do the similar

3:23:51 thing which is grabbing the first three characters but let us say I

3:23:55 want to grab the from the second name which is Kumar I want

3:23:59 to grab M A so how do I go about this how do I

3:24:02 go about solving this with the help of the left function and here is

3:24:05 the catch we cannot do this thing with the help of the left function

3:24:09 and here substring function will help us to do this so from the substring

3:24:13 let us say I am doing what onto the second name column which

3:24:17 is correct and I want to grab the character M A so n

3:24:20 starts with you can just say k is 1 U is 2 so

3:24:25 I'm just counting the character index and M is equal to 3 so M

3:24:30 starts with 3 and number of characters which you want after M so

3:24:37 the number of vectors which I want after M A is equal to 2.

3:24:40 because m is equal to 3 and a is equal to 4.

3:24:44 and R is equal to 5 what is the number of factors after 3 I

3:24:49 want is after the the character which is present at character index 3 is 2.

3:24:54 let us execute this particular query here

3:24:59 and you can see our logic is successful what

3:25:03 we were trying to achieve we have achieved

3:25:06 using this substring function I hope this is pretty

3:25:09 much clear you can grab any set of characters

3:25:10 in between this spring as well as well

3:25:13 as from the left part of the string as well and if you is if you're just

3:25:19 wondering how we can grab how we can

3:25:21 use the substring function similarly to how write function

3:25:25 was working let's say I want to grab

3:25:26 the last two characters from the string so how

3:25:30 do I go about that now this particular string is quite small let's say I have

3:25:34 a string which is too big it has 100 of characters and I want to grab the last

3:25:41 two characters from the string and not using

3:25:45 the right function so just friend just think about

3:25:47 this how we'll be solving this particular problem

3:25:49 with the help of the substring function whatever I

3:25:53 have I have covered into this particular video

3:25:55 is enough to solve that problem so the thing

3:25:59 which I'm talking about is I'll just help

3:26:02 you understand let's say my string is this big and I want to grab the last two

3:26:11 characters from this string using the let's say first

3:26:16 of all we'll use the write function here so let's see how we can do this using

3:26:21 the right function I'll just write here select which you want us to so this will

3:26:31 give into the output as a r similar

3:26:36 thing I want to achieve using this substring function

3:26:39 this string was a small it was a small string so that is why we just

3:26:45 counted one two three but let's say the string is quite big as you can see

3:26:49 into my screen and I'll just just add

3:26:52 any number of characters so we cannot just count

3:26:56 start counting this is not actually the process not

3:26:58 good coding practice that just start counting the number

3:27:02 of characters from which you want to grab so let's say if I want to grab

3:27:06 the last two characters using the substring function so

3:27:08 I'll just start counting K is 1 G is

3:27:12 2 R is equal to 3 B is 4 so I'm counting the character index value

3:27:17 this is the wrong way of solving the problem

3:27:20 so how do I go about solving this particular

3:27:23 problem here so you can just comment down

3:27:25 your approach and the different people can come up

3:27:28 with different type of solutions the most easiest

3:27:31 solution which I can just think of right now

3:27:34 is I'll just use the reverse function which

3:27:38 we have just discussed little back and I'll just

3:27:43 put this and instead of right I'll use the left function to do the same thing I

3:27:53 hope you're getting what I'm trying to say so you can see I am getting the last

3:27:59 two characters which was y and e you can just see into the output I'm getting e

3:28:05 and Y so what I'll do is I'll again reverse the output which we which I am

3:28:12 getting so let's do this reverse and let's

3:28:18 execute this code once again and you can see

3:28:20 I'm getting the right output this time the last item is y e and I'm getting y

3:28:26 e I hope you enjoying me to this particular video you can just see how I'm using

3:28:30 the different type of functions to solve this complex

3:28:32 level of problems uh you can just comment

3:28:34 down your answer below to the comment box

3:28:36 how you can solve particular problem using this substring

3:28:40 function here let us move to the next

3:28:42 function which is present here which is the trim

3:28:46 now the trim function is one of the most used function when it comes to the data

3:28:52 cleaning part exactly it trimmed us I'll just

3:28:55 show you guys the trim is nothing but let's

3:28:59 say the number of characters which is present

3:29:02 here is five one two three four five

3:29:04 and let's say there are some space present here so if I would just get a length

3:29:16 so number five let's say let us say I just want to count the number of length

3:29:20 of characters which is present into this particular

3:29:22 string so I'll use the length function here and I'll hit enter you can see it is

3:29:26 giving me seven now this is weird the numbers

3:29:30 now the the number of characters present

3:29:32 into this string is five but into the output I

3:29:35 am getting a seven this sounds weird but it

3:29:38 is actually not because you can just see I added two strings here so all

3:29:44 of those strings are now counted as a character value

3:29:48 and that is why we are getting the number

3:29:50 of characters as seventh so friends in real

3:29:54 scenarios we'll be facing these problems and let's

3:29:58 say I want to grab the first two characters

3:30:01 from this particular string so ideally the output

3:30:04 which I should be getting is a and r

3:30:08 but let us see let us use the right function to do the same thing so

3:30:15 I'll just write here right and two you can just see them into the output I'm not

3:30:21 getting anything and this is all because the last

3:30:25 two characters are a space bar space which

3:30:29 is present here so this particular problem is

3:30:32 solved using the trim function so let's see how

3:30:35 do we use the trim function so I'll just use the trim function here and I'll put

3:30:43 it put this particular string inside the string

3:30:48 function I'll hit enter and you can see I'm

3:30:50 adding the correct result this time now what

3:30:52 exactly printed trim actually all the space factors which

3:30:57 were present after that string were removed and then

3:31:02 we got exactly the same concept of characters

3:31:05 which you are seeing right now which is k m u a r so there are

3:31:09 no strings there are no space which is

3:31:12 present here after you have trimmed a particular strip

3:31:15 the no space characters which will be present

3:31:18 after the word so similarly let's say I had

3:31:21 space characters before the string and you can

3:31:25 see the number of factors now have increased up

3:31:27 to 11 while you can just see into this string

3:31:30 we can just see five characters and instead

3:31:34 of let's say the light function I use

3:31:39 the left function to grab the first two characters

3:31:41 from this tree and you can see I am getting nothing into my output while you're

3:31:46 seeing nothing actually output which is getting uh

3:31:50 present here is a space bar which nobody can

3:31:53 see ideally so this is the output which we are getting here so how do I solve

3:31:59 this particular problem I want to get the first

3:32:01 two characters from the left hand side which

3:32:03 is K and M so here also I'll use the train function to first of all trim

3:32:09 this particular string and then grab the first

3:32:12 two characters from the left hand side as you

3:32:14 can see onto your screen I have used

3:32:16 the trim function and I have grabbed the first

3:32:19 two characters from the left hand side so

3:32:22 friends this is all about the trim function

3:32:25 for the string also and after the string

3:32:27 also if any space character is present it will remove it and it will give you

3:32:32 the desired result a single thing which is present

3:32:36 into the SQL as well I'll do one

3:32:39 thing I'll add string characters here to the second

3:32:45 name just make this table once again one row

3:33:07 affected a lower section from names okay you can

3:33:13 see you can still see I'm getting space

3:33:17 characters here let us do the same thing so

3:33:21 I'll do a left of second name and I want to grab two characters from the left

3:33:29 hand side similarly I'll do a write of second

3:33:40 name I'll grab two characters from the right

3:33:43 hand side from names that's it I'll just execute

3:33:53 this command what is the output which we'll be

3:33:56 getting can just imagine so you can see

3:33:58 I'm getting into the output nothing actually the result

3:34:02 which you can see onto your screen contains

3:34:05 space characters and that is what we are not

3:34:07 seeing right now so let us use the training

3:34:10 function to do or to remove the space

3:34:14 characters I'll just use film here also and I'll

3:34:22 execute the function you can see we are

3:34:29 getting the desired result or the exact result

3:34:31 which I wanted I am getting the last

3:34:33 two characters and the first two characters here

3:34:35 present which is the upper and lower now before

3:34:39 that there are two different Trends function I

3:34:41 will cover it right now because we just have

3:34:43 covered the atream function so editoring and ordering you

3:34:47 can just think of from Common Sense what does

3:34:49 I trim means so L stands for left so this is a function which simply tells

3:34:55 that the what trim function does it is it

3:34:59 will remove all the space characters from the left

3:35:02 hand side of the string and also from the right hand side of the string as you

3:35:06 could see onto your screen as well but we

3:35:08 have this special function which is L trim

3:35:10 and R trim so L stands for left left side trim which means that it will remove

3:35:16 all the space status from the left hand

3:35:18 side of the string means it will remove all

3:35:21 the space characters from the right hand side

3:35:23 of the string so this is used in this way

3:35:26 let us see uh how do we use this in here so or into this particular

3:35:33 second name you can see some space characters

3:35:36 were present earlier I'll do one thing I'll remove I'll do a hard trim right now

3:35:42 I'll not remove the left hand side characters here

3:35:47 uh for this purpose because I just want to show you how this function is working

3:35:51 and here I'll do a l trim and I'm

3:35:53 grabbing characters from the right hand side so what

3:35:56 do you think into the output what will be

3:35:58 shown according to me the output into the output

3:36:02 it will all be blank what do you think of what it will show I'll just

3:36:06 execute this particular command you can see

3:36:08 into the output we are getting nothing so instead

3:36:12 of R train I'll do while trim and I'll

3:36:14 grab first two characters from the left hand side

3:36:17 and here also instead of L frame I'll do a r train and I'll grab first

3:36:22 to practice from the right hand side now

3:36:24 you can see into the result we are getting

3:36:27 the exact result which we wanted we are

3:36:30 getting the first two characters and we are also

3:36:32 getting the last two characters from the string let

3:36:34 us move to the next set of problems next

3:36:37 set of functions which is the upper function

3:36:41 and the I think I've written trim twice I'll

3:36:44 just remove this always the upper function

3:36:47 and the lower function okay let's see into the Excel

3:36:53 first of all you can see into the full

3:36:58 name of this string the first character certain

3:37:03 in upper case upper case it means that it

3:37:05 is written in capital letters and the other

3:37:08 characters are written in small letters let's let

3:37:11 us say I want to uh completely change

3:37:14 the string to a lowercase characters string so

3:37:19 this right here lower I'll select the string and you

3:37:21 can see all these characters have changed

3:37:24 to lower case similarly let us say I want

3:37:27 to change this character into the upper case

3:37:29 so I'll just select right here upper and select the string and you can see all

3:37:34 these characters have changed to uppercase similarly let us

3:37:38 see e to the Excel as well I'll do a select shot from names and I'll do

3:37:46 a same thing here I will select star from names let us do one thing let us

3:37:54 concat is there a concatenate function here that I've

3:37:59 used I remove the space let us create the table once again okay we have

3:38:13 this concat function ready I'll utilize this only so as full name we have got so

3:38:30 in this full name don't worry whatever I'm doing right

3:38:38 now I'll just make you understand what I'm

3:38:40 doing at a later stage this so this is something as a kind of a substring I'm

3:38:45 putting the result into a substring and I'll use

3:38:48 the result of this particular you know the string

3:38:53 or you know this particular query as my source

3:38:57 and then I'll be working on to that so I'll just try it here select star

3:39:02 from this don't worry I'll just help you

3:39:08 explain everything at a later stage uh right now

3:39:12 Our intention is to learn the left upper and the lower function so let us say I

3:39:18 want to make everything as upward so I'll

3:39:21 just write here a power of full length early lower of so let us change the name

3:39:34 of the columns that's it let's execute the query

3:39:49 and you can see into the output we are getting the exactly the same result what

3:39:53 we we were trying to achieve which we saw into the Excel as well all the vectors

3:39:58 have become the uppercase all the characters have

3:40:00 become the lower case into the third column so

3:40:02 friends this is the use of the upper

3:40:04 and the lower function let us move to the index

3:40:06 function which is concat underscore WS now oh

3:40:10 you just saw that concat is used to join

3:40:14 multiple strings uh into the sequel what is exactly the use of the concat w s

3:40:20 what actually is the limitation in concat

3:40:23 function so there is no kind of limitation

3:40:26 but in Concord you can just see I have

3:40:29 to provide everything in a sequence kind of thing

3:40:32 like that first name and then the space

3:40:34 character the second name and then the space character

3:40:37 then the last name in concat WS we

3:40:40 can join multiple strings whatever we want to join

3:40:45 then and in between all these strings we

3:40:48 can provide let's say if I want to provide

3:40:50 a space character I can just do or give that let us say I just want

3:40:54 to provide you know the comma between all of these names I can just skip that so

3:40:59 I'll just write the syntax and that will help

3:41:01 you understand what exactly concat approach does well just

3:41:05 write your phone select font WS let us

3:41:09 assume that all of these names would contain

3:41:12 a space I'll copy the first name I'll copy

3:41:16 the second name here I'll copy the last name

3:41:19 from here as well from themes let us execute the query you can see I'm at I'm

3:41:32 achieving the same result what what I achieved

3:41:35 in using the concat function I'm achieving the same

3:41:38 result using the concat underscore WS function here

3:41:43 as well paste this and let us execute

3:41:53 the code so you can see in both of my my result the output is same the output

3:42:02 is exactly same difference comes when you're using

3:42:06 it so you're giving multiple times you will

3:42:09 have to give space but here in concat

3:42:11 underscore WS just give a space and then you

3:42:15 are just sorted out you just keep all

3:42:17 the column names which you want to give let's

3:42:19 say you do this set I want to put a comma in between the names and I'll

3:42:26 just select the query I'll execute this you

3:42:28 can just see in between the names we are

3:42:31 getting the comma so friends this is the use

3:42:33 of the concat underscore WS function into the SQL

3:42:37 and this is how we use this let us move to the next function which is present

3:42:42 here which is the difference function and I

3:42:44 assume this is the last function into the string

3:42:47 function section string function actually contains a lot

3:42:50 of different functions so you need to spend

3:42:52 a lot of time here understanding different things

3:42:54 understanding different concepts I think this contains more than

3:42:58 any other kind of data type function so

3:43:00 the difference function difference function do we use

3:43:03 this normally into the real case scenarios generally not

3:43:07 but I'll just help you explain what it actually

3:43:11 does so let us say I'm using the difference

3:43:15 function I have two strings and I'll just

3:43:27 execute this code you can see it is giving me answer as four just think of like

3:43:34 we are entering the string values

3:43:38 but into the output we are getting a integer value

3:43:41 or a number how is this even happening

3:43:44 so what difference function it does is whatever strings

3:43:48 which you will be providing into the difference

3:43:51 function it will just match like how close

3:43:54 these two strings are to each other in terms

3:43:57 of the sound effect so when you just spell

3:44:00 juice and juicy you can just see sound is quite similar and this is ranged onto

3:44:06 the basis of 0 to 4 so 0 means those two words are those set of words

3:44:12 are not closely related while four means

3:44:17 that a set of Words which you're providing is sounding

3:44:20 exactly the same or closely it is sounding

3:44:23 the same which is actually you can just think

3:44:25 of the juice and juicy it is sounding exactly the same so these two set of words

3:44:30 are closely related to each other instead of juice

3:44:35 let's say I've I'm giving my name what

3:44:38 do you think what should be the output I you can see the output comes as to okay

3:44:41 the answer comes as to ideally we don't

3:44:44 use this function uh I haven't used this function

3:44:47 even a single time but I just wanted

3:44:50 to display this out because we're just learning

3:44:52 the string function and this is the use uh

3:44:54 this is all about the difference function as well

3:44:57 let us move to the next section

3:44:59 of the functions so there are various kind of date

3:45:02 type function so as you know date and time is a in itself is a data

3:45:07 type which is present into the SQL because

3:45:09 we will be needing to require to store data

3:45:13 in form of dates in form of time and that is a very critical information for any

3:45:18 particular company so we will be using different

3:45:21 date time function let us see one by one how we will use this now one very

3:45:25 interesting function which is present here is let us

3:45:28 say I want to get the current date and time so how do we how do I

3:45:33 get that so is very simple function which

3:45:36 is Select get data and tool into the output

3:45:38 you will it will give the current date and time which is going more right now

3:45:43 so friends you can see the next function

3:45:46 which is here is the cast function I will come to this later first of all we'll

3:45:51 just discuss this year month and day function

3:45:53 from the name itself it is quite clear

3:45:55 that it will give the day from the date so

3:46:00 into the day function I'm passing the argument as the get date so you can see

3:46:04 the day today is one and also take it here I've got the date I'll get the month

3:46:20 from this as well and I'll also get the year from the get plate let us execute

3:46:36 this particular function before that let us execute

3:46:40 this particular query and into the output you can

3:46:44 see I am getting the current date and timestamp

3:46:48 with timestamp and the current day from that particular

3:46:53 timestamp month and the year and which is

3:46:56 coming out exactly correct so from a particular

3:46:59 date let us say we want to grab the year or from the month or the month

3:47:04 value so we will use this particular

3:47:06 functions which is the month the year function

3:47:08 or the day function as well to grab the date so friends this is the use

3:47:12 of the get date function we saw a lot

3:47:15 of different things like how we are getting the get

3:47:18 date function how are we grabbing the day

3:47:21 from the get date the next function which is here is the cast function now what

3:47:27 does the cast function into cache function generally changes

3:47:31 from a particular data type to a different data type let us say I I have a date

3:47:36 column whose data type is the string data type or the wire data type so when I

3:47:43 am going to apply all of these different

3:47:45 functions which is relevant to the date time

3:47:48 it will not be useful that guess we need to change the data type of the column

3:47:53 the value data type to date time or date

3:47:56 data type and then all of these functions

3:47:58 will happen so let us see let's do one thing I will cast so you can change any

3:48:06 value to any other data type so let us say I want to change integer value

3:48:11 or a decimal value as and let us execute this code and we can see this is

3:48:19 successful so I have given in terms

3:48:23 of decimal number but actually this has got converted

3:48:26 in terms of wirecad data type here this was

3:48:29 all about the cast function let us move back

3:48:31 to a slide and the next function we have seen the year month day cast the next

3:48:37 is the time which is quite relevant that we

3:48:41 can get the time from the a particular

3:48:44 date type column so I'll just select here time

3:48:47 get date that's it let us execute the code we can just see it is showing me

3:48:56 error that time is not a recognized built-in function

3:48:59 name and this I've done this intentionally to make

3:49:02 you aware that there is a year day

3:49:04 or month function need not necessary there will

3:49:06 be a time function so we need to get

3:49:08 a turnaround for this so how should we go about solving this so just saw using

3:49:13 the cache function we can convert a particular data

3:49:16 type to a different data type so this get

3:49:18 data is in a date time kind of data type let us convert this into a Time

3:49:23 data type and get the result so I'll

3:49:27 be using the cast function here so I'm saying

3:49:31 I'm passing the argument that whatever date time

3:49:34 is coming into get date change that to what

3:49:39 time later down that's it let us execute

3:49:42 the query and here we are using the time

3:49:46 function as you can see so I'm just telling my code that generate the get date

3:49:52 from the get date function just get the date

3:49:54 and the time and extract the time and then

3:49:57 display the result and you can see onto my screen into the output I am getting

3:50:01 the time stamp from the particular date so

3:50:05 friends this was the use of the timing function

3:50:07 let us move to the next which is the date add date diff and the date part

3:50:12 now these three functions are one of my favorites

3:50:14 because we use them a lot of many times when we are working on the SQL when

3:50:19 we are solving real life problems in the day

3:50:22 part is a very versatile function you can just Google it out I'll just show you

3:50:27 guys a buddy for font date Partners so

3:50:30 you could just see from the pl function which

3:50:33 we use we can just grab the ear from any particular date we can do this using

3:50:38 the data date part function as well

3:50:40 a lot of different functionalities so let's just say

3:50:42 if I want to grab the year from a particular date so I'll just write here here

3:50:46 and then I'll just write the date here

3:50:50 I'll close the bracket and into the output we'll

3:50:53 be getting the Year from the date so you can see I have got the ear similarly

3:50:57 I can just get the month as well so you can see I'm getting the month as well

3:51:03 and this was the use of the uh date part function let us move to the next

3:51:08 function which is the date add so from the name only it is quite clear that you

3:51:14 are adding something to the date which you are passing so you can add years you

3:51:18 can add months you can even add days to a particular date so let us see how

3:51:23 we are using this particular function and it's

3:51:25 for data to look something like so I'll just

3:51:29 write here select date add I'll open my bracket

3:51:33 I'll write what is that component which I

3:51:37 want to add to a particular date so let's say I want to add the ear component

3:51:41 so let us say I want to add one year to a particular date so I'll just

3:51:45 write here as here comma 1 comma and get date that's it let us close the bracket

3:51:52 I'll execute this particular query and you can

3:51:57 see a year has been added the current

3:51:59 date is of 2023 but here right now you can see the day which I am getting

3:52:05 is of 2024 I will get indicated function as well into one of the columns so

3:52:11 this is the current date and time and this is

3:52:14 I've added one year to the current date

3:52:16 and time using the date add function as you can see let us see if I want

3:52:20 to get go a year back so I'll use a minus 1 to do this and you

3:52:25 can see I have gone to a minus one date so it was 2023 it is 2023

3:52:31 right now and I've done a minus one and the date which is shown here is of 2022.

3:52:36 so friends this is the function this is the use of the date add a function

3:52:40 here for more interesting function into the date

3:52:42 which is the date tips now from the name only it is quite clear that from two

3:52:50 different dates we can just grab the difference

3:52:52 in terms of years in terms of months in terms of days so let us do one thing

3:52:57 let us grab in terms of the difference in terms of years from the get date like

3:53:05 the today's date and I'll do one thing

3:53:11 on today's date only I'll go some random number

3:53:19 of days back and I'll get the difference

3:53:24 in terms of yields let us execute this particular

3:53:27 query and you can see the answer which

3:53:30 I'm getting is seven so what this has done

3:53:32 is so it has got the difference between this state and the today's date so you

3:53:40 can just mention what is the difference in what

3:53:43 terms do you want to get the difference so I want to get difference in terms

3:53:46 of year so I've passed the argument that gave

3:53:48 me the difference in terms of years and then

3:53:51 I have provided the dates on which I want to get the difference now you'll tell

3:53:55 me of those what is this get date minus

3:53:57 2.53 it's looking quite weird there is nothing

3:54:01 but from today's date it has gone I've just

3:54:05 put a random number so it has gone two four five three days back I'll execute

3:54:10 this code and you can see it has gone to a date which is of 2016 a random

3:54:18 date and it is getting a difference between

3:54:19 today's date and this date roughly you can

3:54:22 just see the difference comes out to be

3:54:24 seven years the difference is there here let's see

3:54:28 if I want to get the difference in terms of the months what should be the answer

3:54:33 to the answer would be quite simple it

3:54:35 will give the difference in terms of months let

3:54:38 us say if I want to get the difference in terms of days now what will be

3:54:42 the answer of this it's quite clear

3:54:43 from the query itself if you will just quickly see

3:54:46 the answer would be 2 4 5 3 because

3:54:49 from the today's date I'm going to these many

3:54:52 days back and I'm just getting the difference in terms of the day so it will

3:54:56 return two four five three only so friends

3:54:58 I hope you are finding this quite interesting

3:55:00 mind you take different data are the most

3:55:03 used function into this was all about the date

3:55:06 time function let us move to the next

3:55:07 section uh and let's see more more functions are

3:55:11 there so we'll be discussing some mathematical functions

3:55:14 and the I've covered all the mathematical functions which

3:55:17 I generally use in my day-to-day time

3:55:19 into into my day-to-day tasks here so let's see

3:55:23 the very first function first of all I'll just

3:55:25 discuss this power function the power concept is quite

3:55:28 clear it is quite simple let's say to to the power 4 so what does this mean

3:55:34 so this means that 2 is multiplied four

3:55:39 times and the result would be something like 16.

3:55:43 so this is the mathematical definition of power how

3:55:47 we can calculate this or do this into this sequel

3:55:50 let us see so I'll just write here power

3:55:54 and two comma four I just need to provide

3:55:58 I'll close the bracket and you will just see

3:56:01 the result which we are getting so you can

3:56:03 see I'm adding the exactly the same result so

3:56:06 the answer was 16 we are getting here is 16.

3:56:09 I'll just add a very big number here so that you can just see if

3:56:15 we are able to calculate the power of big numbers or not okay this has

3:56:19 overflown and that is what because SQL also has some limitations into it and it

3:56:25 can store a certain set of characters value and that is why it is showing

3:56:29 that arithmetic overflow error converting expression to data

3:56:32 type float so we need to change

3:56:34 the data type of this particular column to convert this or to get the answer

3:56:39 but ideally this is the normal definition of power and this much this is enough

3:56:42 for clearing any interviews if anybody asks what

3:56:45 is power function they'll just you need to provide

3:56:47 two arguments the base as well as the power and the power will be

3:56:51 calculated the answer will be calculated let

3:56:53 us move to the next function which is the round function now what is this round

3:56:58 function so I'll just take put the select

3:57:02 round I'll take a random number here and let's see this is a decimal number

3:57:09 if you want to get only two digits after the decimal place right now what

3:57:15 you can see is I am having one two three five six six characters after

3:57:19 the decimal places I just want to get

3:57:22 two characters after three decimal places how

3:57:26 should I go about solving this so to solve this I'll just use here comma 2.

3:57:32 and this will be rounded off to two decimal places

3:57:37 as you can see here right now so 345.46 is

3:57:42 the answer which I'm getting rest of them are zero

3:57:45 after decimal places zero does not have any value so

3:57:48 you can just clearly see this entire decimal number is

3:57:53 converted to two decimal places of a small place I

3:57:56 mean this I'm achieving using the round function now you

3:57:59 can see the number has changed and this happened this has

3:58:02 happened because the last Vector then the second last Vector

3:58:05 you can see here is five and after that 7

3:58:08 is present so according to mathematical rules this would

3:58:11 be rounded up so five four becomes six so if

3:58:14 this number is greater than uh Pi or Phi

3:58:18 the previous number will be rounded off that is why it

3:58:21 is fitting it is becoming as 0.46 and answer which

3:58:24 we are getting is correct let's move to the next function

3:58:28 and this is one of the interesting functioning function which

3:58:30 is the seal and the floor function and these are

3:58:33 some of the interesting functions and the behave in a kind

3:58:35 of unique way so these functions they help us

3:58:39 to solve a good level of problems complex problems as well

3:58:43 so for serial function and the floor function I have

3:58:46 the example ready from before to help you understand how

3:58:49 does the ceiling function works and how does the floor function

3:58:51 works so in in normal terms what the ceiling

3:58:55 means and what this floor means so let's say I'm

3:58:59 in in a room the top most part is the ceiling

3:59:02 and the lower most part is the floor similarly the same

3:59:05 Concepts applies into this sequel as well so for a number

3:59:09 which I provided here which is 25.75 I am

3:59:13 told to calculate the ceiling and the flow what the ceiling

3:59:16 means sealing it just means that what is the higher

3:59:21 level of this particular number in terms of integer

3:59:24 and similarly floor means what is the lower number in terms

3:59:28 of integer for the number which you are providing

3:59:30 as you can see here I am giving a ceiling

3:59:33 of 25.75 so which is the integer number which is

3:59:38 the closest to 25.75 you know I want to go

3:59:43 into the ceiling so I need to go above which

3:59:46 is in terms of Greater number so after 25.75 which is

3:59:50 the nearest closest integer number which comes which is greater

3:59:55 than 25.75 so I hope the conditions are quite clear

3:59:59 so to get the answer the number should be greater

4:00:02 than 25.75 first of all and it should be the nearest

4:00:09 to 25.75 so both of these conditions are mandatory

4:00:17 for the ceiling function so which is that number will satisfy

4:00:20 that criteria so let us execute this code to get

4:00:23 the answer so you can see the number is 26 so

4:00:27 the number is greater than 25.75 which is true

4:00:31 and the number is nearest to 25.75 the integer numbers I

4:00:36 just started teacher number nearest to 25.75 which is true

4:00:44 the thing which we have done for ceiling which is

4:00:47 just opposite for the flow of value as well so

4:00:50 I'll just change the power of our first floor so

4:00:53 to make flow to get the answer from this flow

4:00:56 function the number should be less than 25.75 and the interior

4:01:03 money is to 25.75 this particular condition remains as constant

4:01:10 so I'll just select this particular query what do you

4:01:12 think what should be the answer the answer is 25

4:01:15 because 25 is less than 25.75 which is quite clear

4:01:19 and 25 is that integer number which is nearest

4:01:22 to 25.75 which satisfy this project criteria so there are two

4:01:27 different criterias which we need to take care when we

4:01:30 are using the ceiling and the floor function and two practitioners

4:01:33 which you can see onto your screens for instance

4:01:35 this is was all about the different mathematical functions which we

4:01:39 have into the sequel let's move to the next section

4:01:41 and we will be learning about the aggregate function which is

4:01:45 present into this equal now mind you the aggregate function

4:01:48 are the most used function into the SQL whenever we

4:01:53 are doing any day-to-day tasks whenever we are putting data

4:01:56 cleaning tasks data manipulation data representation so all of these things

4:02:00 are taken care by the aggregate function which will be

4:02:03 seeing right now onto our screen so to help you

4:02:06 understand aggregate function I have a separate acceleration ready

4:02:10 with me here which contains some data set I'll just help

4:02:14 you explain about this particular Excel sheet it is not

4:02:17 that much complex it is quite simple in nature because

4:02:20 the first hit section the very first column I have

4:02:23 the districts name into the second column I have the state

4:02:27 name into the third column I have the area

4:02:29 in kilometers and into the fourth column I have the population

4:02:33 of that particular District so you can read the information

4:02:37 something like in this particular District which is let's say

4:02:41 Agra into the state uttar Pradesh the district area is

4:02:45 four zero four one square kilometers and the population is

4:02:49 44 lakhs something like that so this is how we

4:02:52 read the information now you will tell me how do I

4:02:55 get to know about the aggregate function from this data

4:02:59 set so in aggregate function there is one important concept

4:03:02 which is the group by concept Group by concept

4:03:09 for all those people who are familiar with Excel pivot tables

4:03:14 so let's solve two problems here or let's say let's

4:03:18 solve four problems here the four problems which I want

4:03:22 to solve is something like total area of all rate

4:03:30 total population of all things let's say I want to solve

4:03:44 both of these problems how do I go about solving

4:03:48 these two problems here with the help of the pivot

4:03:50 table it's quite simple I'll go to insert I will

4:03:54 go to pivot table I'll select ok I'll get this interface

4:03:59 I hope people were not familiar with pivot table don't

4:04:02 worry it's quite simple these are some simple steps we

4:04:06 took so per state let's say I want to calculate

4:04:10 the total population and it only again kilometers so friends

4:04:16 you can just see I'm getting the state and the total

4:04:20 population in the state and the total area then

4:04:23 what is the total population so if I just click

4:04:26 on to one of the section you can just see

4:04:29 the total population which is populating right now

4:04:32 on to the let's say I'll just choose I'll choose BR so

4:04:36 I'll just select this total population which is populating right

4:04:40 now in Bihar state the number which you can see here

4:04:45 which is 964 something so what is this number

4:04:48 so this number is the sum of population of all

4:04:52 the distant population which is present in Bihar state so

4:04:56 all the districts which are present in Bihar State they will

4:05:00 have a certain population which you can see into the sheet

4:05:03 one so if I just filter out the district

4:05:07 or let's say we stayed from here which is Bihar

4:05:13 you can see all these districts have a certain populations attached

4:05:18 with them and we have all this information so the final

4:05:21 answer which you can see here in Bihar this answer

4:05:25 is the sum of all the population of all

4:05:28 the districts of Bihar so this is the answer which we

4:05:31 are getting right now on to a screen with the help

4:05:33 of the pivot table now friends if I'll click

4:05:37 on this the hard section you can just see all

4:05:40 the the data set I've got from which I am getting

4:05:44 that number so this is the use of the pivot

4:05:46 table but how exactly this is working I'll just show

4:05:49 you guys this group by function so what is happening

4:05:52 is all these similar things in into this particular column

4:05:56 are getting grouped so when we are telling that group

4:06:01 by Under the basis of the state in other terms

4:06:04 I've just said that group bio to the basis

4:06:05 of the state and calculate the population so the result would do

4:06:10 something like or the query it will works internally something

4:06:13 like let's say the Bihar state it will be filtered

4:06:19 out I'll do a control C I'll just present

4:06:23 this value somewhere else and let's say I'll just take some

4:06:27 other State here as well let's say I'm taking Andhra

4:06:38 Pradesh right now I'll do a control a control C

4:06:42 I'll go to my next file so internally what will

4:06:46 happen is all the States data will be segregated or will

4:06:52 be differentiated by the SQL Server I'll pick some one

4:06:57 more State let's say I'll take a sum for now

4:07:04 so similarly I'm just done right now because of time

4:07:08 constraint for only three states but similarly internally how

4:07:12 the query it will work is will tell the code

4:07:15 to calculate the total population or total area in square

4:07:19 kilometers in in terms of the state as you can

4:07:21 see onto my screen I've done this using the pivot function

4:07:25 into the SQL so how this internally works is all

4:07:30 these different data sets will be segregated likewise Bihar Andhra

4:07:34 Pradesh Assam so similarly all the other states data sets

4:07:38 will be segregated so into this particular data set so you

4:07:42 can just think of it as a subset from the total

4:07:45 set of data which is present or the total

4:07:49 dump of data which I am having into my sheet

4:07:51 one so all these different sets of data would be segregated

4:07:55 or differentiated and on to these different sets of data

4:07:59 the value will be calculated so the the answer will

4:08:04 be something like it will be for Bihar it will

4:08:07 be something like the sum of all the values which

4:08:12 is present in the population column for this set

4:08:15 for the Bihar set so this is how the population

4:08:19 of Bihar is calculated similarly the population of Andhra would

4:08:24 be calculated something like it will be a sum of all

4:08:28 the population districts population which is present into Andhra Pradesh

4:08:33 similarly for Assam also it will be sum of all

4:08:37 the district population which is present into the ascent so

4:08:40 how the query internally it is working it is something like

4:08:45 on which column we are telling that I want to calculate

4:08:48 the population on the basis of these states the state

4:08:53 is that column on which I am telling my code

4:08:55 to group by and to group by it will do

4:08:58 something like all the distinct values which will be present

4:09:01 into the state column that would be segregated differentiated separately

4:09:07 and then on to that particular set of data the calculation

4:09:11 will be happening and will be seeing the final data

4:09:14 into the pivot table or the all the or the group

4:09:18 by function when we'll be using into the sequence

4:09:21 friends I just wanted to demonstrate this first of all

4:09:23 into the Excel sheet and then we'll be importing the Excel

4:09:27 file into our ssms and that way we'll also see

4:09:30 how do we import the Excel file or any data

4:09:33 which we are having into the Excel file into the SQL

4:09:35 Server management Studio because just think of I have

4:09:39 around 641 rows into this sheet and how manually tiring

4:09:44 the process will even if I go on to insert

4:09:47 Inn at each and every node data into my SQL

4:09:49 Server management studio so it will means importing the Excel sheet

4:09:53 in our SQL server and we'll be doing the same

4:09:56 thing which we have done right now onto our screen

4:09:59 or to the SQL Server management studio so I

4:10:01 hope it is quite clear how Group by function internally

4:10:04 this work here so first of all let's let us

4:10:06 say I'll just summarize it again we have this dump

4:10:09 of data and we are being told to calculate the total

4:10:12 area of one state calculate the total area of all

4:10:15 the state we have the information in terms of the district

4:10:19 wise so for which district into a particular State

4:10:22 we have that particular information so we want to calculate

4:10:25 the area for this state so we'll be using the group

4:10:27 by function into the SQL but the same thing can

4:10:30 be achieved using pivot function or the pivot table in Excel

4:10:34 how the group by function or how pivot table internally

4:10:37 this functioning is it is something like it will take

4:10:40 into account the entire data and then it will store

4:10:44 somewhere else and then it will count the total number

4:10:47 of distinct values which is present into the column

4:10:51 on which we want it to group by now just remove

4:10:55 the duplicates from this particular column so I've got all

4:10:58 the distinct states which are present into my data set

4:11:02 now one by one what will happen is information will

4:11:07 be filtered out one by one well I am having Andhra

4:11:10 Pradesh so I will filter out the Andhra Pradesh information

4:11:13 from here so society around the Pradesh and this is

4:11:20 the exact information which I want I'll open a new

4:11:24 sheet I'll put the state information here I'll go back

4:11:28 to my sheet so this is how the code internally

4:11:32 is working I hope this is pretty much clear because just

4:11:35 learning about the code or the system it will not

4:11:38 help it will only help if we learn how the code

4:11:41 internally it works how the code processes the data

4:11:44 and that it will help a lot to solve complex level

4:11:47 of problems or to help to get a general understanding

4:11:51 when we are writing a particular query we are just

4:11:53 not writing for the sake of getting the data we

4:11:55 are writing with proper understanding how it will internally work

4:11:59 and calculate my result so the next state for the matter

4:12:03 of fact is uttar Pradesh so I'll just filter

4:12:06 out the data for uttar Pradesh okay load once again

4:12:17 so this is the relevant data for uttar Pradesh which

4:12:20 is required so this will again be copied it will

4:12:23 again be you know segregated so similarly all the states

4:12:27 data will be segregated and at the last stage it

4:12:31 will be grouped by so for Andhra Pradesh the answer

4:12:36 would be something like on through Pradesh and into the next

4:12:43 column we'll be having so this is the shade column

4:12:47 and the next column we have the sum of population

4:12:54 and this the result would look something like sum

4:12:58 of these values similarly for uttar Pradesh this would look

4:13:07 something like uttar Pradesh so I'm just showing the output result

4:13:11 and the final result which will be getting after doing

4:13:14 a group by so I'm doing the sum of this following

4:13:19 and you can see and waiting this sum so friends

4:13:21 this is how the group by function it works let us

4:13:25 see let us execute the same thing into this simple

4:13:27 I hope it is quite clear how grouper function internally

4:13:30 it is working now you can Group by Under the multiple

4:13:34 bases and onto the basis of multiple uh multiple columns

4:13:39 as well so for example let us say I have a state here and I was zoned and I have

4:13:47 the sales number I have this state 1 uh let's

4:13:53 say in zone Z1 the total cells it'll be something 50.

4:13:59 State 1 zone two the sale say somewhat it's a 40 I'll have another

4:14:06 column which is of the month let's say and this will be five for I'll

4:14:15 just add random number zero so in this month the month number is five

4:14:21 in this state into this Zone the total sales that has happened is 50.

4:14:26 and I'll have more let's say in State One in zone one month number and three

4:14:38 since it's 90 for any values here number five so I'll just copy this I paste

4:14:45 this here okay great so let us say I want to calculate the total sales by state

4:15:03 in there zones so if you would just think of how do I go on to solve

4:15:11 this particular problem so if I want to calculate

4:15:13 the total sales by each of the state

4:15:16 into each of these Zone so this is a kind of tricky problem because we

4:15:21 cannot use the state column here just to do a group by because let's say if

4:15:27 I do a group by onto the state column I'll be just be getting a single

4:15:32 single column here and that would be under

4:15:35 the basis of the state so the in which

4:15:39 I'm talking about is into the first follow my lab the state and I do

4:15:43 the second column my lab with some

4:15:45 of the sales which is not ideally the result which

4:15:49 I wanted ideally the thing which I wanted

4:15:51 is something like I want to get the total

4:15:53 sales by the state and also by the zone so to add the zone I'll just

4:15:59 pick up the zone and put it into the rows or let's say I'll put it

4:16:03 into the columns so you can see I'm getting for the state S1 in zone S1

4:16:12 I am getting the total sales as 140 Zone Z2 I'm getting the total sales as 40.

4:16:18 so I want a similar kind of result using the group by function so

4:16:22 how will this internally internally it will work so into this SQL so we can

4:16:29 use the group by function to solve this particular problem as well so first

4:16:33 of all what will happen is on to which columns we need to group by so

4:16:39 the result would look something like into the state S1 for the Zone Z1

4:16:44 the total sales was some amount so I'll just write it here so the output would

4:16:52 look something like this so state zone

4:16:55 and total sales similarly state in a different

4:16:59 Zone the total sales the second state

4:17:03 in the zone 1 tutorial sales into the second

4:17:07 uh state into the zone 2 the total cell so we want to get

4:17:13 the output in some of this manner so let us say let us see how do

4:17:18 we do this into this SQL so we'll be grouping by Under the basis

4:17:22 of the two columns here because we we want to get the total number of sales

4:17:28 aggregated onto the basis of these two columns

4:17:30 so we'll be grouping here onto the basis

4:17:32 of the state column as well as the Zone column so how will this board

4:17:36 internally it will work so the the funder Remains the Same first of all we

4:17:42 will copy these two columns and we will go to data tab we will remove

4:17:47 the duplicates from these two columns so

4:17:51 these will be the unique values or the unique

4:17:54 combinations which are remaining right now I have just have two columns you can

4:17:58 do group by into as many as columns you want the Funda should be clear

4:18:03 the idea should be clear how internally it will work so I'm just showing you

4:18:07 how the SQL query internally manipulates the group

4:18:11 by function so first of all it

4:18:13 will I have the entire dump of the data it will copy the data it

4:18:18 will generate distinct combinations which are present

4:18:21 so in my previous example I would have

4:18:25 to do a group under the BC of the state column to calculate the total population

4:18:28 so that is why I just I just picked up that column and it did

4:18:33 a distinct of all the num values which I'm having into that column right now

4:18:37 I am using two columns to do group by so internally what SQL will do

4:18:43 is pick up those two columns and a distinct

4:18:46 combinations which are present so by distinct

4:18:49 combinations what I mean is this is my entire dump of data set which was

4:18:53 present let us see which combination is repeating so both of these columns I am

4:18:59 talking as a combination a combination as a kind of a pair so this is

4:19:05 S1 Z1 this is one Z2 similarly this is S1 inside one is to Z1

4:19:20 H2 S2 Z1 so this is the combination you can just think of which I

4:19:30 am getting here right now so friends how many you can just think of which

4:19:37 values are repeating here so S1 Z1 I have a value here I'll just mark

4:19:42 this with a different color S1 Z2 I have of different value here which I

4:19:49 am having which I'm getting some Market

4:19:51 with a different color s1z1 so previously did

4:19:59 I found find any combination operations yes it is there into the first row so

4:20:03 I'll just mark it into the same which is the red h2z1 did I find

4:20:10 H2 Z1 into the above rows you know so I it is the distinct entry

4:20:15 which I'm getting here right now so

4:20:16 I'll mark this into a different color similarly

4:20:20 S2 Z2 was there a entry of h2z2 previously no the answer is no so

4:20:25 I'll smoke it again with a different set of color H2 Z1 was there entry

4:20:31 of H2 right yes there was an entry of a student Z1 but I think

4:20:35 before so this is also duplicate entry which I am getting here right now

4:20:41 so friends you can just see s1z1 this one Z1 they are repeating so all

4:20:49 those values which are similar they will

4:20:51 be uh you know distinguished or segregated as a kind of a different data set

4:20:56 and then the group by function will happen onto

4:20:58 that similarly H2 Z1 and S two Z One those two are duplicate values so

4:21:05 all these values will be segregated differently

4:21:07 and then the group by function will happen

4:21:09 onto that thing which will happen immersility

4:21:11 it will as I discussed it will remove

4:21:14 the duplicates from the combination you can

4:21:16 just see four unique values for the combinations

4:21:19 are remaining right now so we want to calculate the sales onto the basis

4:21:25 of the SE particular combinations which I'm getting

4:21:28 right now I just paste this separately here

4:21:33 so first combination is S1 Z1 so what equal will do is we will go

4:21:39 to the applied filter will first of all select S1 from the next column it will

4:21:45 select Z1 this data will be segregated it will be kept aside somewhere the next

4:21:54 distinct value which we have got here is S1 and Z2 so similarly it will

4:22:02 apply the filter on S1 it will apply the filter on Z2 we are getting

4:22:10 only a single row entry I'll copy this it will paste it like this now

4:22:18 the third entry is S2 and Z1 so instead S2 will be selected okay we'll

4:22:26 just swap is because we have entry for S2 and Z2 the last one so

4:22:31 this will be pasted here and the third entry was S2 and Z1 we are

4:22:39 getting the values so this is how

4:22:44 for all the combinations we will be filtering out

4:22:47 the data and will be presenting here as you can see right now onto

4:22:52 your screen I do one thing I would

4:22:56 delete this so friends these are these different

4:23:02 set of combinations which we have got different set of grouping which we have

4:23:08 got from the data set which we wanted I'll do one thing and I think

4:23:15 on the side color here so that you can just think of all

4:23:19 of these different groups which have been created

4:23:21 with the help of the group by function

4:23:24 and how Group by function internally it will

4:23:26 work I'm just clearing out first of all

4:23:27 that concept data will move to the part of the code because writing the part

4:23:33 of the code is not that important understanding

4:23:36 the concept is important so from this entire

4:23:38 data set the problem was something like

4:23:40 algorithm totals sales by state and these zones

4:23:43 so this was my problem and how did I go about solving this or how

4:23:50 SQL internally it works to solve this particular

4:23:53 problem first of all it will get

4:23:55 the entire data set it will paste the data set it will it will do

4:23:59 a distance of the combination of columns on which do you want to group by so

4:24:05 here you can just see I wanted to calculate the sales by state and this zone

4:24:09 so I picked only those two columns I pasted it I deleted the duplicate

4:24:14 combinations which I was getting so for all

4:24:17 these combinations it will calculate the aggregate

4:24:21 of the total sales so the next step is something like S1 and Z1 is

4:24:27 first combination so what SQL will do is first of all from the entire set

4:24:31 of data it will filter out the data where state is equal to S1 and zone

4:24:36 is equal to Z1 so we have filtered out the data for S1 and Z1

4:24:40 coming to the next combination which is S1 and Z2 what will the function it

4:24:46 will do internally it will work first of all it will go to the state

4:24:49 column it will filter out the data for the stated as S1 and then Zone

4:24:55 as Z2 now the final thing what will happen is you can see I've got

4:24:59 four different states I've got the different zones

4:25:02 and the last step is calculating the total

4:25:05 year so the total will just be like this calculating this sum over all

4:25:15 these different Aggregates which we have generated combinations

4:25:21 which we have generated so for the combination

4:25:24 of S2 and Z1 which is that combination so it is S2 and Z1 which

4:25:29 we are seeing so it will calculate

4:25:31 the sum for this particular combination and similarly

4:25:35 it will generate of sum for H2 and Z2 now friends you will think why

4:25:41 asturs is spending so much time here

4:25:43 to explain these Concepts into so much detail

4:25:46 and this is all because it is necessary to understand how the query internally

4:25:51 it is working rather than just you know just going through the code at upper

4:25:56 level not understanding a deeper level because

4:26:00 these things they matter a lot when you're

4:26:02 writing the complex queries in future so

4:26:04 this will these things these small things will

4:26:06 matter a lot you will be able to analyze you will be able to think

4:26:09 how this group I function internally it

4:26:12 is working friends from that perspective this is

4:26:15 very very important I hope the group by function is very clear how the internal

4:26:20 functioning will happen how everything is working

4:26:22 internally you can Group by into the basis

4:26:24 of the multiple columns as well I'll do one thing I'll just show you an example

4:26:29 into my SQL Server management studio uh

4:26:33 I'll import the data set of the population

4:26:35 which I just showed you before I'll import it and I'll just show you

4:26:40 how do we import the Excel data into SQL Server management Studio I have ready

4:26:46 from here but I'll do one thing I would delete this and I'll reinsert it

4:26:52 again for all of you guys so that you also understand how this is happening it

4:26:57 has been deleted after you're doing any action

4:27:00 just refresh this to see if the changes

4:27:03 are visible or not so to import the data set I'll go to the database

4:27:10 which I've created I'll go to tasks I'm going to import data it will

4:27:15 give me interface which is something like

4:27:18 this which you can see onto your screen here from the drop down I'll select

4:27:21 a Microsoft Excel because I am importing Excel

4:27:25 file which is same as data sets too I'll just select the file and click

4:27:29 on next you might get this error as well so you need not to do

4:27:33 anything um I am also getting a lot of many times this particular address so

4:27:38 what I usually do what I've usually seen

4:27:40 I don't know the solution for this there

4:27:43 are two things first of all just open the data set or on in Excel

4:27:48 as well just keep it open uh the time when you are reporting the second

4:27:52 thing which I've seen is just phone

4:27:55 selecting the lower version of the Excel some

4:27:57 odd real things will work you can just see the older version work for me

4:28:02 similar things you can also try and select

4:28:05 okay my bad I'll select SQL Server native

4:28:08 client URLs click on next I'll wait for some time and click on next now

4:28:15 okay and click on into one click on next next initiate so the sheet1 was

4:28:29 nothing but you can just see I have a lot of many sheets available so

4:28:33 it was just showing your information like which

4:28:35 particular sheet data do you want to import

4:28:43 as you see this what might have happened but the idea I think is very

4:28:47 clear how do we go on to import any data set uh let us refresh

4:28:53 this to see if we imported it successfully or not okay you can see I've

4:29:03 got I've imported it successfully as as mentioned

4:29:10 we are getting all of these values

4:29:12 from the sheet one you can just see data set to is the sheet which

4:29:16 you can see right now and while explaining you all of you guys I just

4:29:21 added some new columns and all of these have been added right now I'll do

4:29:27 one more thing I would just close this I'll do a no don't save and I

4:29:35 would open the data set once more or the Excel file once more this is

4:29:40 right now it's clear we will do one thing and you can just skip

4:29:49 from two three minutes more because what I'll do is I'll just import the same

4:29:55 sheet again or if you want to follow me you can just follow me simply uh

4:30:00 that will add to your practice as well so first of all we need

4:30:03 to go to our database tasks import data the steps are quite simple here you want

4:30:11 to import Excel file just select the Excel file browse the Excel file in which

4:30:18 you have the data present click on next you might get an error as what

4:30:22 I'm getting right now select uh older version from here make sure the file

4:30:27 is open on your system it is active as select your SQL Server native client

4:30:34 and click on next next next this time you can see no more sheets were

4:30:40 showing up this is the benefit of SQL

4:30:43 Server management Studio you can see the data

4:30:47 has been imported now how would I can see after doing any changes the study

4:30:53 first is go to tables you can see the details data or table which we

4:30:58 had created earlier and this is the data which have been imported I'll do one

4:31:04 thing I'll rename this as which means population data of course um okay it has

4:31:15 been changed so I'll just try this let's start from pop let's see if

4:31:18 this works or not okay we are able to see the data or not and you

4:31:21 can see it is telling invalid object name is pop so I'll do one thing

4:31:26 I'll just write here ddo.pop talking so then

4:31:30 I'll provide your my database name and you

4:31:36 can see finally we are getting the data and what actually happened is we when

4:31:41 I guess when we are having multiple tables here we need to go from the root

4:31:45 directory so we need to students into dbo into the pop that my data

4:31:50 is present so just do a select star and get my data out so you

4:31:53 can just see here we are having the information so while you are just

4:31:57 coding while you're doing these main things a lot of many times you'll be facing

4:32:01 these small small shoes we need not to take care of all these small issues

4:32:04 this will happen a lot of many times so uh our main concern is to understand

4:32:09 the concepts how the code internally it will work how the code works so

4:32:13 and learning different functions so the first problem

4:32:17 was to calculate the state wise population so

4:32:22 what is its index so this index is something like select sum of population State

4:32:31 and the sum of area underscore kilometer

4:32:38 Square from this because my data is present

4:32:45 there this is the total off and this is the total area that's it is

4:32:57 that enough that is execute the query let's see if the query is throwing any

4:33:02 error I will definitely throw an error because let us see let us quickly see

4:33:07 what the error is whenever you're writing a query the error will the error which

4:33:12 will be thrown into the console it will it will solve half of your debugging

4:33:17 because into the error itself it is quite

4:33:20 clearly mentioned what do you need to do

4:33:22 we'll just clearly read out the error what it is shown so it is telling

4:33:26 column something is invalid column state is

4:33:29 invalid in the select list because it is

4:33:31 not contained in either an aggregate function

4:33:33 or the group by Clause because if you

4:33:35 will just see I'm just telling the code to display certain columns I have never

4:33:39 told the the code on how do you need to get the sum or how

4:33:44 do you need to calculate the sum so here comes the use of the group

4:33:48 by function so we need to tell our code group biometric basis of this state

4:33:54 so after this all that things internally it will happen it will get the distinct

4:33:58 values from the state column then it will segregate all the states Forum data

4:34:03 from the the entire data set which I am having the master data set which I was

4:34:07 I was having and then calculates state

4:34:10 level population data and it will generate

4:34:13 the result let us say if you're getting the correct result or not and you can

4:34:18 see we are getting the correct result we have the state we have the total

4:34:21 population we have the total area as well let us do one thing what we

4:34:25 have seen is I'll order by so

4:34:29 whatever state whichever state is having the highest

4:34:31 population I want to get it into the top row and into the descending order

4:34:36 basis of the Eastern population so you

4:34:39 can see uttar Pradesh has the highest population

4:34:43 also all these things we can do into this ego you can just see how we

4:34:47 are slowly slowly gradually moving towards solving

4:34:51 complex level problems we have seen Aggregates here

4:34:53 you know friends the problem which we

4:34:56 have solved into the data set everything I've

4:35:00 deleted the data set from here but I'll do one thing which is I'll generate

4:35:06 a similar kind of data set first of all I'll create a table here which

4:35:56 I'm setting right now on to my table which is the field so let's do

4:36:00 a select star from sales let us see what is the output which we are

4:36:05 getting right now so you can see I'm getting the correct output I'll do

4:36:12 the same thing which I've done onto the Excel sheet as well I want to know

4:36:16 in a particular state in a particular Zone what is the total number of sales

4:36:20 which have been generated using the let's say the group by function I want

4:36:23 to solve this particular problem so the problem is and if you lead total sales

4:36:31 on each State and a Zone so here we'll be using select state name comma sum

4:36:44 of sales so by state name so friends what do you think will be able

4:36:50 to solve this particular problem of calculating

4:36:52 the total sales on each state in June let

4:36:56 us see the answer so you can see our purpose is not solved because we

4:37:01 are getting only a single column here which

4:37:03 is of this statement so in this particular

4:37:05 State the total number of sales is this now this particular say stay the total

4:37:09 number of sales is this but we also want on the basis of the zone

4:37:13 so here what we need to do is add a new column which is

4:37:16 the zone so state name Zone name

4:37:19 and the total sales will just provide this information

4:37:24 I just showed you guys previously how

4:37:26 this thing internally it'll work into the SQL

4:37:29 query I hope that has helped you and you can see we have the desired

4:37:34 information ready if I would like to summarize it it will be something like

4:37:38 the combination on which you will are grouping

4:37:41 by the combination all this combination will be

4:37:44 picked up the distinct from all these combinations will will be able to get

4:37:48 and then on to basis of all

4:37:50 the distinct combination we are applying the sum function

4:37:54 and we are getting the answer likewise so friends I hope this was quite clear

4:37:58 let us see on to our presentation what all we have here so friends we

4:38:05 have learned about this group by function

4:38:08 another thing which is here is this having

4:38:12 function now how this this having function

4:38:15 it works so friends having function it only

4:38:19 works after you have grouped by so it only works out to the basis

4:38:24 of the group by function so to apply

4:38:26 the having function a group by function should

4:38:29 have been applied now why why do we need to apply the group by function

4:38:33 and that is because let's just do one thing I'll just quickly make the same

4:38:41 data set which I was having so the thing which I was wanting was sales

4:38:52 on the basis of this State on the basis of this Zone the total sales

4:39:01 now friends let us just quickly revise

4:39:05 this concept once again so those two columns

4:39:09 on which I need to group by I'll present this year somewhat separate detail so

4:39:16 the SQL query internally first of all

4:39:18 it will take distinct values whatever it will

4:39:21 get so the first combination is S1 and Z1 so it will pick the S1

4:39:31 from the next it will pick up the same one will copy it and let

4:39:39 us paste it somewhere else the next combination is also of S1 and Z2 so

4:39:45 let's do it here only right now to save time so this is S1 and Z2

4:39:53 second combination or the third combination is S2 Z2 plus pick up this paste it

4:40:02 here and the final combination is of S2 and Z1 we will select this and we'll

4:40:13 paste this out so we have got the all the desired result which we were

4:40:19 wanting we have segregated all these results

4:40:22 all the different combinations which we have got

4:40:25 uh which we could have got of the state State as well as of the zones

4:40:36 this we have discussed previously also but I just wanted to help you guys out

4:40:42 to revise your concept so I'll just

4:40:44 color this out to distinguish all the different

4:40:48 combinations which we have got so friends I hope till this table is quite clear

4:40:54 all the different groups have been created

4:40:57 right now now after these groups they have

4:41:00 been created let us say I want to generate the total sales on the basis

4:41:07 of S1 and Z1 so the answer would look something like this copy

4:41:12 this for this phase this so far from all these groups of four books have been

4:41:16 created from all these groups I'll get the sum of the sales so S1 and Z2

4:41:26 right S2 and Z two one create and S2 and Z2 okay great so

4:41:38 this is the final output which we wanted to get this color this out of it

4:41:47 so that it looks a bit nice okay so this was the final output which

4:41:54 we wanted using the group by function

4:41:55 now where is this having function is coming

4:41:57 into the picture the having function comes into the picture when let's say

4:42:01 from this final result also which we have

4:42:04 got after the fun after all these Group

4:42:07 by things have happened let us say I want to get the results of all

4:42:13 those all those States and all those zones

4:42:16 where the total sales is greater than 1000.

4:42:22 so I am only concerned or the output is only

4:42:26 concerned of all those States and all those zones where

4:42:29 this total sales is greater than 1000 rupees I hope

4:42:34 the problem statement is quite clear even if we have grouped

4:42:37 by from all of these groupings also I want to get

4:42:42 that particular group information in which the total sales is

4:42:46 greater than 1000 rupees so let us see let us

4:42:51 see which all groups qualify for that so the total sales

4:42:55 for S1 and Z1 is 76 rupees total sales

4:42:59 for S1 and Z2 is 432 rupees total sales for S2

4:43:06 and Z2 is 67 rupees and total sales for S2

4:43:10 and Z1 is something 46 000 rupees so this column is just

4:43:16 renaming as total sales for the group I'm not writing

4:43:22 combination so that you are familiar with the group term so

4:43:26 this column is the total sales of for the group

4:43:29 which we have got now we are only concerned the problem

4:43:34 signal I'll just write here it the details of the state

4:43:43 and Zone having sales employee third and one thousand

4:43:52 this is what my problem statement and this was my output

4:43:56 which I was reading previously but does this particular thing

4:43:59 satisfies my condition which is getting the details of the state

4:44:03 and Zone having sales greater than 1000 so which all

4:44:06 rows qualifies for this these two rows are disqualified because

4:44:12 you can see the number 76 and 432 is less than

4:44:18 one thousand so ideally you should not have come up

4:44:21 only one row would come up which is for six thousand

4:44:24 four forty one because this summer is greater than 1000

4:44:28 and that is the result which I wanted so from all

4:44:31 these groups also I want to apply one more filter

4:44:34 condition where after this result this result will be produced

4:44:39 and from this result the final result which I'll be getting

4:44:43 here is of only those particular State and Zone value which

4:44:48 is having the sales greater than 1000 rupees so this is

4:44:53 my final answer which I should be getting right now

4:44:58 which you can see onto your screen so friends this is

4:45:02 all about how the having function also works so we'll

4:45:07 have to write a particular condition where we need to tell

4:45:09 the code that after you have grouped by or calculated

4:45:13 the total sales or whatever you have calculated it could

4:45:17 be average it could be count after that also you need

4:45:20 to apply a particular condition on all these groups and filter

4:45:24 out the data based on the conditions which have been

4:45:27 given the condition here was the sales for the zone

4:45:31 and the state should be greater than 1000 rupees so all

4:45:35 these combinations first of all we segregated them then calculated

4:45:39 the total sales for the state and the zone and after

4:45:42 we have got this information we we presented this information

4:45:46 in a particular table and after we have presented this information

4:45:49 in a table uh then we are applying a filter

4:45:51 condition where we are just checking into the total sales

4:45:55 column which row is having or which combination is having

4:45:58 the sales greater than 1000 and this is my final result

4:46:02 which I'm getting here using the I think by function

4:46:06 so friends this is how the having by function internally it

4:46:09 will work I hope this is quite clear to you

4:46:13 I'll apply the same thing into this SQL Server right now

4:46:17 uh let's say here I'll do the same thing

4:46:20 for the state and the Zone name let us generate the results

4:46:24 for only those States and those zones serving sum of sales

4:46:29 greater than 1000 also one more thing is having you

4:46:36 can just think of it is similar to the where

4:46:38 clause earlier I was getting much more results if you just

4:46:53 think and just see I was getting one more entry

4:46:56 which is of S1 and Z1 that will sales for 666.

4:47:00 the numbers are quite different in both the section because

4:47:03 into the Excel sheet I've just picked some random numbers here the numbers

4:47:06 are quite different so numbers would not match the results would

4:47:10 not match but the outcome is the logic would be remain remain

4:47:15 the same so you need to see um when I'm not

4:47:18 applying the having Clause like having some sum of total sales

4:47:21 of the combination greater than 1000 when that when I'm not applying

4:47:25 this I'm getting a value here of s1z1 having electron sales of 666

4:47:30 I'll comment this out I'll apply the having by close so

4:47:33 that I'm getting the all the combinations who are having the same

4:47:36 is greater than 1000 and I'm getting the desired result action

4:47:39 as you can see here onto your screen now friends there's

4:47:43 a subtle difference between the where clause and the having by clause

4:47:45 and this is a very frequently Asked interview question to be

4:47:49 sequel so what is the difference is you have seen how working

4:47:52 by cross works it works only the group so after the groups

4:47:56 they have been created so to apply the having weight loss

4:48:00 in addition is that it should only be used with the group

4:48:03 by class the only condition well where Clause it can be

4:48:07 applied on the entire data set itself let's say using the where

4:48:11 Clause I just want to filter out the rate of for only

4:48:13 the state one from this entire data set so where Clause

4:48:17 it will just apply the S1 filter onto the entire data set

4:48:22 and get the relevant information so from this and particular entire data

4:48:26 set I have got the data set data for all the entries

4:48:31 where state is equal to os1 so this is actually the application

4:48:35 or the where Clause it simply filters out the data

4:48:38 from the from the data set which I'm having while having by Clause

4:48:43 it will filter out the information from the groups which will be

4:48:47 creating using the group by function so I hope that this all

4:48:50 these complex funders and concepts are quite clear by now let's

4:48:55 move to the next functions which will be seeing so likewise

4:49:00 we applied the sum function we can apply the average

4:49:03 function on the all the groups the count function the maximum

4:49:07 and the minimum functions as well for the group so what I'm

4:49:12 talking about is letters do one thing letters I hope the having

4:49:17 by Clause is quite clear I'll just remove this for Simplicity

4:49:19 to help you understand all of these different aggregate functions so I'll

4:49:23 do a select start from sales you can see I'm getting

4:49:26 the details in the table one thing that is like this here I'll

4:49:42 execute this code so you can see for S1 and Z1

4:49:47 we are adding total count this is not total sales so

4:49:52 this is total something totally produced put it for now something totally

4:49:57 so for S1 and Z1 we are getting total as to what

4:50:01 is this total because for S1 Z1 we are having two entries

4:50:05 so that's why we are getting nearest to S2 and that one

4:50:14 here we are getting two entries so we are getting the answer

4:50:17 as two next is S1 and Z2 S1 and Z2 here

4:50:22 and S2 and Z2 for this combination there is just one

4:50:28 single entry present in the entire data set so that is why

4:50:31 we are living the result as one so friends this was all

4:50:35 about the account function similarly there is this average function as well

4:50:40 which will calculate the average of the group which we are

4:50:44 having which we are creating here we use the sum function correct

4:50:51 from where we use the app here so to calculate the sum

4:50:55 of the this combination we use the sum function similarly we

4:51:00 can use the average function to know the average sales which

4:51:04 is being generated by a particular state we can use the average

4:51:09 function here as well so so you can see here I've used

4:51:16 the average function to calculate

4:51:17 the average sales generated for this particular

4:51:21 combination which is state name and Zone name so this is

4:51:25 how it works here also I'll just Supply the average function which

4:51:31 is coming out as 432 because you just have an entry

4:51:35 here and that's it by 432 divided by 1 will be 432.

4:51:40 uh here 32 divided by sum divided by counts total number of entries is 2 sum

4:51:52 divided by 2 will result in 38 so 76 divided by 2 it will generate 38

4:52:01 so this is the average value which we are getting onto a screen similarly we can

4:52:06 use the average thing here and we'll calculate

4:52:09 our results so we are getting the average

4:52:11 value from all of these combinations next function

4:52:15 which we are seeing onto our screen is

4:52:17 the maximum and the minimum function likewise same

4:52:21 thing let's say for this particular combination I

4:52:25 want to get the maximum Max so you can see I'm getting 44 because for S1

4:52:32 and Z1 all these entries which we are

4:52:35 having which is that maximum number which I can

4:52:38 find out so 32 44 two numbers I'm having right now onto my screen the maximum

4:52:44 is 44 because 44 is greater than 32 normally my answer is 44 here similarly here

4:52:50 I can just apply the marks and you can see from getting 5654 before 45654 is

4:53:06 greater than 787 so similarly we can apply

4:53:10 the same thing into the SQL Server management

4:53:12 Studio I'm just showing you guys how do we apply the function I hope I have

4:53:17 helped you with the concepts into a lot of more detail I have taken a lot

4:53:21 of time here but once I have explained this I don't think you'll be having any

4:53:26 doubt any problem when you're solving any complex

4:53:29 level problem also similarly for Min we are doing

4:53:33 this and similarly for Max we have done

4:53:36 this now for instance is a unique function

4:53:40 which is the list aggregate function will be

4:53:43 coming back to this at the later stage

4:53:45 when we'll be learning about the window function

4:53:47 now this is also a part of the list aggregate function now if I would have

4:53:51 to summarize quickly onto this list aggregate function

4:53:55 I will just do this let's say I have the ID I have the items IDs

4:54:07 let's say one one okay one the items is let's say I want my two 53

4:54:20 by 4 and the result which I want is something like ID and in the items

4:54:26 I would like to have all these values

4:54:32 separated by comma so this is the result which

4:54:37 we want and this cannot be done using

4:54:39 the group by function you just think of just

4:54:41 think of doing this using the group by function but you cannot do this or if

4:54:45 you have if you come up with a unique Solution please do mention in the comment

4:54:48 box of this video but this can be

4:54:51 easily solved using the list aggregate function because

4:54:54 here also you can just say you can you are aggregating based on the ID

4:54:57 all the items so I just put this into the aggregate function what will be seeing

4:55:03 this into a lot of more detail when

4:55:05 we are learning or some advisable Concepts later

4:55:08 on and syntax also for this particular function is

4:55:11 quite simple in nature let's move to the next

4:55:14 is the most important part of the SQL and that is the SQL joins let

4:55:20 us continue with joins which are present

4:55:22 into the SQL points which you can see onto

4:55:25 your screen right now this can solve some

4:55:27 high and complex level of problems as well

4:55:30 so basically we have five type of joints

4:55:33 which are present in the SQL number one is

4:55:36 the left join the number second is the right join number third is the inner join

4:55:41 number four is the cross join and the number five one is the full outer joints I

4:55:46 have a very good image here right now

4:55:48 which you can see onto your screen this particular

4:55:50 image will help you to get a very

4:55:52 basic understanding on how these joints and what

4:55:55 do they mean when we tell like we'll do a left join we'll we'll be doing

4:55:59 a right join when we'll be doing a inner join so what does these things actually

4:56:04 it means should be solving uh two three

4:56:07 problems on the SQL joins how these joints

4:56:10 internally it will work like how we saw in the group by function I'll help you

4:56:15 understand all the joints also they will internally

4:56:17 walk into the SQL so friends basically we

4:56:20 have four different kind of joints which you

4:56:22 can see onto your screen the cross join

4:56:25 is absent here I'll help you understand don't

4:56:27 worry so the left join here so the two

4:56:29 circles which you can see onto your screen into each of the joints let us assume

4:56:34 that those two circles are different tables uh

4:56:38 so in left join what actually happens is

4:56:41 you will get all the results from the left part of the table and also all

4:56:46 the matching results between the right part of the table and on the left part

4:56:51 of the table so this is actually what happens

4:56:54 in the left join in left join you'll be

4:56:55 getting all the matching entries by matching entries

4:56:58 I mean when the circles are overlapping into each

4:57:02 other that means that those entries are matching

4:57:05 so basically this is one Circle this is

4:57:07 the other Circle and they are overlapping

4:57:09 in this area so this area is common between

4:57:12 both of these circles so this area is matching it is exactly the same into both

4:57:18 of these circles so we can just say that it will return the matching results

4:57:23 as well as all the results from the left part of the table which we are joining

4:57:30 vice versa exactly the opposite of what it

4:57:33 happens on the right join it will give all the results from the right hand side

4:57:39 of the table which you are joining and also

4:57:42 which the matching reports from both the table

4:57:45 the third table which is the inner joint

4:57:47 so in inner join what actually happens is

4:57:50 it will give the matching results from both

4:57:53 the tables so you can see this is the left table and this is the right

4:57:56 table and the area which is matching

4:57:58 or which is intersecting which is common in between

4:58:01 both of these tables that is marked in blue and this image I have copied

4:58:06 from learn sql.com so this particular website also

4:58:10 contains some awesome resources to learn SQL so I

4:58:13 just wanted to do the credits so you can just see here this particular section

4:58:17 the common section it is marked as blue

4:58:21 I will join what happens is it will return

4:58:23 all the results from the left hand part

4:58:26 of the table as well as as from the right

4:58:29 hand part of the table as well as the matching records in other words

4:58:33 I can just translate it as something like

4:58:35 it will return the matching records as well

4:58:38 as as non-matching records which are present

4:58:41 into both of these tables so first we'll understand

4:58:43 this into a lot of more detail with the help of simple example so let us

4:58:48 move first of all to the Excel sheet

4:58:50 as usual because in Excel generally the things

4:58:54 becomes quite simple to understand first of all

4:58:56 so I'll have a table one created and I'll have a table two created we'll see

4:59:03 the outputs of left drawing right join inner join

4:59:07 and full auto join and also Crossing what

4:59:10 actually it means so first of all provide a student name here in both the parts

4:59:23 and I'll provide the marks and their address

4:59:31 and the output which I want is something

4:59:34 like put which I want is something like student

4:59:39 name the next column I want the marks and into the next column I want to know

4:59:45 what is their address so this is the output information which I want from both

4:59:49 of these tables let us give some sure name as1 S2 S3 S4 S5 S6 I'm just

4:59:57 putting some random names here these names does not have any value let us put

5:00:03 their marks so I'll just put some random

5:00:06 Marks here as well foreign name here I'll do

5:00:18 one thing I'll put few of the students name and few of the student's name I'll

5:00:29 just leave that is how we'll be learning

5:00:31 to join how does all the different joints

5:00:33 they will work and in address I'll just

5:00:36 put some random numbers so friends let us

5:00:39 say let us assume for a matter of fact that we are doing first of all

5:00:43 the left join it will lift done correct

5:00:48 so what will be output into this particular

5:00:51 case when we'll be doing a left join here so what did I say so left

5:00:56 joining what so left joining into the left hand side so you can just see

5:01:00 in this image we have a table we have a circle on the left hand side we have

5:01:05 a circle onto the right hand side so let us assume this case the left side

5:01:10 table or the left side circle is the first table here the table one is the first

5:01:17 Circle the left hand side of the circle and the table to the right hand side

5:01:21 of this circle here what we are left joining so left joining table one with able

5:01:31 to will see this into a lot of more detail with syntax how these things

5:01:34 they will work in SQL also when SQL Server management studio so the output first

5:01:40 of for the very first condition is you

5:01:43 can see from the image itself all the rows

5:01:46 all the entries from the leftmost part

5:01:47 of the table will be copied and pasted so I'll

5:01:50 just so I'll just paste it exactly how

5:01:53 it is because all the entries from the left

5:01:56 most part of the table will be pasted all the matching records from the right

5:02:01 hand side of the table will be presented so what is common what is the common

5:02:06 thing on which we'll be joining both

5:02:08 of these tables so which is that column you can

5:02:11 just say which is common into both of these tables so the common column is none

5:02:17 other than the student's name column which is

5:02:20 common so I'll just mark this with a distinct

5:02:25 color name column is common and on the basis of the common column only we'll

5:02:33 be able to join both of these tables I hope that concept is quite clear we

5:02:38 have identified the common column on which

5:02:39 we'll be joining both of these tables will

5:02:41 start joining so as I mentioned in left

5:02:44 join all the entries from the leftmost part

5:02:46 of the table will be generated while only

5:02:49 the matching records or the common records in the right

5:02:53 hand side of the tables will be will be getting while all the other reports we

5:02:57 will not get so in this case what is matching so let's say will S1 be

5:03:01 able to join so do we fight for S1 let's say are we finally any S1

5:03:06 uh data yes one student data here yes we are getting that is A1 so

5:03:10 the address is A1 similarly okay this should

5:03:17 be S2 sorry my bad so I'll just change

5:03:21 this to S2 similarly for us to do we find a entry into the second table

5:03:26 in the students name column for S2 yes we have so if this record this H2

5:03:33 will be joined with this S2 and then the data will be presented in in a single

5:03:39 row after they've join so for S2 the address is A6 so this data will be

5:03:43 presented next is s3d we have a entry for S3 yes we have entry for S3

5:03:49 and that is A2 as you can see so in the address we'll be getting

5:03:53 an A2 or if S4 do we have a entry for S4 and we can you can

5:03:58 see this no entry for S4 which is present here that means what will be what will

5:04:04 be the answer which we'll be getting here

5:04:06 this will be null because that simply means

5:04:09 that we don't have any entry in the right hand side of the table for the student

5:04:15 name as S5 so for S5 we don't have the information on the address so

5:04:20 that is why we are not able to calculate it sorry that was student number as 4.

5:04:26 so for S4 do we have information on the address no we don't have so that is

5:04:30 what is coming out is null let's move to the next which is the S5 so

5:04:34 do we have nt4 S5 and that is correct we have entry and that is A3 so

5:04:38 A3 will come up similarly for S6 do we have an entry for S6 no we

5:04:45 don't have so what will come up null

5:04:47 because no matching records have been found for S7

5:04:51 similarly do we have entry no we don't have entry for sa do we have entry

5:04:57 yes we have an entry and which is A4 correct and for S9 similarly do we

5:05:05 have entry no we don't have so this we will learn for S10 we have a entry

5:05:10 as you can just see the address is A5 so we'll be getting a 5 here

5:05:15 so friends this was all about the left join so left joint table one with table

5:05:22 two we are doing let me color this with a different color rate let us move

5:05:30 to the next which is the right join and we are doing the same thing right join

5:05:37 table one with table two now mind you

5:05:40 this particular sequence will matter a lot so

5:05:43 right joining table one with table two if

5:05:46 you interchange if you need to change this term

5:05:48 write down table two table one the result

5:05:50 will totally vary the result is totally dependent

5:05:53 on how you are joining the table how

5:05:56 you are providing the sequence so let's say here

5:05:58 I am providing right joining table one

5:06:00 with table two the result will be let's say

5:06:03 the result is R1 and if I do right so in table two with table one

5:06:08 the result will be quite different it will

5:06:10 work all differently so friends this is the catch

5:06:13 here so please be aware on the sequence

5:06:15 on which you are joining all these different

5:06:17 tables that matters a lot into the sequence let us move a little ahead and let's

5:06:23 see how does this right join it actually

5:06:25 works so according to the right Zone it will

5:06:28 give all the record from the right hand side of the table and also the matching

5:06:32 reports between the table which is present it

5:06:36 will give into the output so first of all

5:06:38 the very first thing which should be clear is it will give all the results

5:06:42 from the right hand side of the table so

5:06:46 the table which is coming onto the right hand

5:06:48 side is the table two so all the records from the table to will be copied I'll

5:06:53 just copy this all the requests from the table

5:06:55 to because in right join all the records

5:06:57 from the right hand side of the table it comes and it will join it will

5:07:03 right join with table one and only matching records will be able to get so it is

5:07:08 let's say it is marks so first of all it will check okay for S1 do

5:07:13 we do I find an entry for this one yes it is there the marks is 66.

5:07:18 let us say for S3 do we find as the entry

5:07:21 for S3 yes it is there the marks is 95.

5:07:25 similarly for S5 two final entry for S5 yes we have 94 S5 the marks is 76.

5:07:33 similarly for S8 it is 80 or S 10 which is 91 and for S2 it

5:07:41 is 96 so this is how we are getting all the mods of let us say

5:07:47 let us assume for this particular case there was a student whose ID is s 11

5:07:51 and number and the address is something like

5:07:53 A9 Hello friends into this particular case what do

5:07:59 we have a entry like we'll be getting all the all the results from the right

5:08:05 hand side of the table that is quite clear so I just added a row here

5:08:08 so that is why I should add it here also because all the results from the right

5:08:11 hand side of the table we should get part s112 we have marks for student IDs

5:08:17 S11 no so what should be the result in the marks column it will be

5:08:21 none because there is no magical record which

5:08:24 is being found after we are joining both

5:08:26 of these tables so friends this is how the light joints uh it works into the SQL

5:08:31 coming to the inner join and this is

5:08:35 the most interesting thing of how inner join works

5:08:38 so inner join will only give into the output

5:08:41 the matching records correct will not give all the records The Columns are clear

5:08:49 but the output is not clear so in the First

5:08:52 Column after we are joining both of these stable

5:08:53 onto the basis of the common column which is the student name will be getting

5:08:57 these three columns that is for sure let us see what are what are what all

5:09:01 common entries are present into both of these tables

5:09:04 so the first student S1 Mark says 66 2 we have address for S1 yes

5:09:10 it is there and the address is A1 so I'll just write here S1 66

5:09:18 A1 percent restarted for the next student S2 the marks is 96 do we have a entry

5:09:29 for H2 with the second table yes we have the address is A6 let us move

5:09:35 to the next S3 do we have a address for S3 and that is A2 and the marks

5:09:41 is 95 let us move to the next S4 do we have entry for S4 no

5:09:54 we don't have so that is why the records will not match because the inner join

5:09:59 we are only concerned with the records which

5:10:02 are matching in both the tables so friends

5:10:05 you can see there's no entry for S4 so that is why we will not get

5:10:10 any entry for S4 similarly for S5 do we have entry yes we have so

5:10:14 for S5 it is 76 and A3 so it's 570 six and A3 that's all let's come

5:10:24 to the next which is S6 do we have military 4 is 6 no we don't

5:10:28 have so you will not return the results

5:10:30 because no matching entry is being found for S7

5:10:33 do we have a matching entry no there's

5:10:35 no student whose address is S7 is coming out

5:10:38 S8 we do have entry and the address is A4 and the marks score this is 80.

5:10:48 let us move to the next which is s92 we have a entry

5:10:52 for S9 no we don't have last if S10 and for S10

5:11:00 we have on the marks coming out as A5 and okay

5:11:09 the address is A5 sorry my bad and the marks is 91.

5:11:15 so that's all that's all is it correct

5:11:18 no it's not correct because there this S11

5:11:22 student also which is present we should which

5:11:25 we should definitely check so is S11 present

5:11:29 here no it is not present so no entry would come up here so in inner

5:11:33 join there's no concept of null which will

5:11:35 be coming because only will be getting matching reports

5:11:38 which are present into both of these tables

5:11:41 coming to the next which is full outer

5:11:44 drawing let us see how does this work so I'll just write here full outer join

5:11:53 to inflow to join what happens is actually

5:11:55 it will give the matching records as well

5:11:58 as the unmatching records from both of these tables

5:12:01 so friends first of all we'll figure out

5:12:04 the matching reports which we have got here is like this so we have got all

5:12:11 the matching records which are present here let

5:12:13 us get all the unmatching records the records which

5:12:16 we did not get to match so S1 S2 S3 so S4 the student name has

5:12:22 S4 we were not able to match the report so that is why we are not getting

5:12:28 the record for S4 similarly for S6 and S7 there is no matching record which was

5:12:37 found into the second table so that is why we are getting a null value similarly

5:12:42 for S9 so we have got all the unmatching

5:12:46 records from the first table when we are

5:12:48 joining with the second table now there can

5:12:50 be another another case also there can be some

5:12:52 records which are present into the second table

5:12:54 for which we did not find any entry

5:12:56 when we were matching so which is that row so that row is the S11 you

5:13:01 can just see for S11 we did not find any marks or any marks for S11

5:13:11 so it will look something like S11

5:13:13 and the marks column it will be none because there

5:13:16 was no marks we just found and into the address column there this will be

5:13:20 A9 as you can just see here so friends

5:13:22 this is the total operation of the full outer

5:13:26 join as you can see onto your screen this is how the full routers don't need

5:13:30 to work first of all these are all

5:13:32 the matching records I'll just drag this down so

5:13:40 this is all the match records which I'm assuming to both of these tables this is

5:13:44 the records which are unmatching records from table

5:13:54 one to table two so these are all those entries and this is just the opposite

5:14:06 unmatching reports from table two to table one that's

5:14:16 it and this was all about want to be joined so this is table one two table

5:14:22 two I think it is I'll just copy this down this is the brief onto

5:14:31 the full outage right joining the left join

5:14:35 now friends this is another concept which is

5:14:37 on to this cross join cross join it works so to make cross joint work it is

5:14:43 nothing but for each entry into the table one

5:14:48 it will match with all the entries which is

5:14:50 present into the table two for example if I'll just explain you guys so this row

5:14:58 first of all I move to a new sheet itself one column is this your name

5:15:05 column let us say we are doing a cross showing so what will be the output

5:15:08 so in corrosion the output looks something like

5:15:10 a common column on which we are joining both

5:15:13 of these particular table so each entry

5:15:17 from the table one will be joined with each

5:15:21 entries from the table to irrespective of any

5:15:24 condition so on joining the result will be

5:15:28 something like this so friends this so for S1 each in for S1 it will join

5:15:41 which with each of the entry into the table second so you can just see this is

5:15:46 the cross join condition similarly next it will

5:15:50 move to S2 it will again join with each

5:15:54 of the entry into the table two and this H2 will be provided likewise next is

5:16:02 S3 so we'll copy it will paste it here it will do the same thing again

5:16:11 and again for every other case so similarly

5:16:16 it will happen on until unless the student name

5:16:19 is S10 so this is the basic thing on how Crossing works it is also popularly

5:16:24 known as Cartesian product which means that each

5:16:27 each entry you are multiplying with the other entries

5:16:32 in the other table so you can just

5:16:34 think it something like S1 you are multiplying

5:16:38 with each of the entries in the other

5:16:40 tables similarly H to you are multiplying with each

5:16:43 of the entries in the other table simile S3 S4 S5 S6 S7 as8 you are

5:16:49 multiplying with each of the entry into the other

5:16:51 table and S10 as well similarly the logic

5:16:54 works iteratively for each of the entries so

5:16:57 this was all about the cross join and how

5:17:00 this works into the sequel so friends let

5:17:03 us see all of these songs and their syntax

5:17:06 how do we use them into the SQL Server management studio so first of all I

5:17:12 will do is simply create a table what we did into the Excel and I'll just

5:17:22 copy this thing I'll give you the syntax

5:17:26 and then I'll apply the different joints to show

5:17:30 you whether the answer which we got into the Excel is correct or not I'll create

5:17:36 table sensors what is the columns which are

5:17:38 included go to the sheet okay student name

5:17:45 marks and students go to my Excel sheet

5:18:05 channels copy here I have all the values which

5:18:26 were exactly same into the Excel let us

5:18:29 quickly verify if the concepts which we have

5:18:33 learned here into the Excel sheet about the different

5:18:35 joints whether we are reading the same results or not when we are doing the same

5:18:39 thing into the SQL Server management Studio One

5:18:43 By One you'll see all the joins so first of all let us see if we left

5:18:46 join so the syntax of left join will

5:18:48 be something like select from details left join

5:18:57 details one on so this table is the first

5:19:06 Circle which you did see onto the previous

5:19:08 screen and this table is the second Circle

5:19:11 so details left join details one on so we will have to specify or tell

5:19:17 into our code which is the common column on which

5:19:19 you are joining and on which you are trying to join both of these tables so

5:19:23 the common column on which I'm trying to join both of these tables out so I

5:19:27 will have to mention a table device so it will be details dot so it will

5:19:33 display all the columns you can see marks

5:19:35 as understanding are the columns which are presented

5:19:38 to the details table so I'll have to write here details dot s name details 1 dot

5:19:48 so as soon as you give a DOT you can see all the columns which are present

5:19:52 into the details one table is now being

5:19:54 displayed and here also I'll have to select

5:19:56 s underscore name because that is the common

5:19:59 column on which we'll be joining both of these tables you would wonder why did

5:20:03 I not mention your any other column name

5:20:06 or I could have mentioned a star but I don't want to be here star because I want

5:20:10 to give only three relevant columns which I

5:20:12 want so first of all the column which

5:20:14 I want is the name of the student second column which I want is the marks

5:20:25 of the student so you can see the solution

5:20:27 is being shown the third column which I want here is the address of the student

5:20:37 so I'm just pressing into the details one table

5:20:40 so from which table I want to grab

5:20:43 that particular column information I'll have to mention

5:20:45 first of all the table name dot whichever

5:20:49 column you want to grab the information from so

5:20:51 this is the kind of flow so I'm just writing from details one table so this is

5:20:56 the details one table as you can just see the second table here enter the output

5:21:02 so I want to get the address column so I would just copy this address

5:21:07 for them from here I'll paste it here

5:21:12 everything is done now I'll execute the code you

5:21:16 can see I'm getting the exactly the same

5:21:18 set of results which I got into the Excel

5:21:22 sheet so from this thing our understanding is

5:21:25 pretty much correct the result which we call

5:21:27 is exactly correct so for S4 you can see null we are getting for a six

5:21:33 we are getting snull so we'll just quickly verify S4 it was null S6 it is

5:21:39 null so friends why did I first of all show into the Excel so that it

5:21:43 is quite easy for you guys to understand

5:21:44 how these joints they internally it will work let

5:21:48 us do for left join as well you can see the number of rows are also

5:21:52 the same so we have 10 rows and here also we are getting the 10 rows now

5:21:57 the next thing which I want is I wanted to work with right join so instead

5:22:01 of left I would just substitute with the word

5:22:04 right I'll execute the command you can see

5:22:07 in addition to that new result has come

5:22:10 up with null null values and only address

5:22:13 column which is present here and this also

5:22:15 makes sense because we will be getting all

5:22:18 the all the entries from the right most side of the table if you remember I

5:22:22 had I read this row at a later stage and here you can see I mentioned here

5:22:27 S11 here it is coming out us now because there was no marks we just found

5:22:33 for S11 name shoe in particular I wrote as S11 we are reading the student name

5:22:37 as well because all the entries from the Left

5:22:40 Right more side of the table we should

5:22:42 get but into the result you can just see we are getting out as null why is

5:22:46 this happening this is happening because you can

5:22:49 just see from the details table from the above

5:22:51 table we are capturing the student's name

5:22:54 and we'll do the above table the details

5:22:57 table there is no name of the student with student ID as S11 so there's no

5:23:03 entry only so that is why it is showing out as null so instead of details I

5:23:07 should add your details one and when I'll

5:23:10 run this particular query I'll execute this you

5:23:13 can see I am getting the student name

5:23:15 as well so these small small things also matters

5:23:19 a lot or many times because you can just see changing the name of the table

5:23:23 from which you are designing the values and you're

5:23:26 getting the column details it matters a lot

5:23:28 of many times so this this is the how we are solving this particular issue first

5:23:32 the issue was earlier we had only details stable and in details table do we have

5:23:37 a name for student ID as S11 no we don't have so until an unless I want

5:23:43 to get the student name details from the details

5:23:47 one table we won't be getting the name

5:23:51 S11 as S11 so this was the difference which we were seeing this was all about

5:23:56 the right join it's quite simple to understand

5:24:06 it's nothing but the inert shown this result it's

5:24:14 quite simple you can see I'm getting all

5:24:16 the common results between both of these tables

5:24:20 and this also is exactly matching from our Excel sheet so S1 S2 S3 S5s then it

5:24:30 is the same details which we are getting the same which we bought into the Excel

5:24:34 file the next one was the full outer

5:24:37 join find it that these small things will matter

5:24:47 the column or the table from which you

5:24:50 are deriving the column values so the results

5:24:54 which we might be getting will be different

5:24:56 from what we have done into the Excel sheet

5:25:00 so friends you can just see this one S2 S3 S5 I'll just quickly present

5:25:06 this it here to match the results those are

5:25:16 all matching records you can see for all

5:25:20 these values I'm getting null value because

5:25:22 those student name for all these were not present

5:25:26 into the second table so when I'll be changing

5:25:30 this to details instead of details one I'll execute

5:25:34 this code in details table we have all the students name with those marks so we

5:25:40 are getting the entry as you can see into my Excel file as well I am

5:25:46 getting S4s 6s7 S9 only in the last row you can see s 11 is not

5:25:56 coming and here it is coming out as null

5:25:58 because we are getting the same concept we are getting the name of the students

5:26:04 from the details table and details table does not

5:26:07 contain any name of the student ID as S11 so that is why we are writing here

5:26:15 as null if I change it to details one you will be getting to see all

5:26:20 the entries from the second table so we'll

5:26:23 see you can see S11 is coming while all these values are null because for all

5:26:28 these entries we did not find a matching name

5:26:31 into the second table the concept is something like this so I hope it is pretty

5:26:35 much clear from Cross join you don't even

5:26:37 need to provide all of these conditions because

5:26:40 there is no concept of common column here

5:26:42 so just mention all the table names just do

5:26:46 a cross join that's sit and you can see a lot of menu records we are

5:26:49 getting as I mentioned into the example

5:26:52 in the Excel sheet you would remember each entry

5:26:57 from one of the table will be joined

5:27:01 with each other entries into the secondary friends

5:27:03 this is how we are solving or this is

5:27:05 exactly the syntax of the Cross join let us

5:27:09 solve a very interesting problem in SQL

5:27:11 this is one of the commonly asked interview question

5:27:14 onto the sequel what is the question so

5:27:17 this was a very simple level concept onto

5:27:20 the joints but a higher level concept is

5:27:23 coming up right now I'll just show you onto my screen I have a data set ready

5:27:29 from before quite simple I'll copy this and I'll

5:27:37 execute this the two data sets which I would like to join here is Select start

5:27:46 from table one select from table two I'll

5:27:57 execute the code it is quite simple just

5:28:04 copy this is Socrates here what I'll do is I'll do one thing I would help

5:28:16 you explain just about the left joint concept and I'll leave up to you on how we

5:28:24 are solving or what should be the result

5:28:26 when we are joining both of these tables

5:28:31 when we are doing the right drawing when

5:28:33 we're doing an inner join pull out a join

5:28:35 cross joining into all those cases what should be the result I would leave it

5:28:40 to you I would help you explain the left

5:28:42 join concept how what will be the output in case of left join when these two

5:28:47 tables are joining onto the basis of the left

5:28:50 joint so first of all how will this thing

5:28:53 work so friends let's say into my previous case if you would clearly closely see

5:28:59 those having distinct values into my column what will

5:29:03 do this particular case you can see values

5:29:05 are getting repeated into next row so you can

5:29:08 see one is getting repeated similarly three is

5:29:11 repeating into the first table into the same

5:29:15 table you can see two is repeating also one more thing is you can see null

5:29:19 values are present so what will happen when

5:29:21 we are joining with null values does that even

5:29:24 happen like do we join null with something can we join none so we'll see all

5:29:30 these different concepts the first one doing

5:29:33 a left join so the output would be something

5:29:37 like one one I just first write the output for you guys this is my first table

5:30:03 this is my second table output which I am getting when I am doing a left

5:30:07 showing here for the tables the output is

5:30:10 something like this now I'll let you know how

5:30:12 we are getting this our particular output

5:30:14 and this thing is each of the similar entries

5:30:18 which is present here will be joined

5:30:20 with each of the similar entries from the editable

5:30:24 for example what do we what do we mean by similar entry so you can see

5:30:28 here one so it will join with one year so do I find the one here yes

5:30:34 I find I can find a one here so this one will be joined with this one

5:30:39 so we are getting the first row this is clear the first one is clear

5:30:43 to the second part this one will be joined with one so is one present in table

5:30:50 two yes it is present you will find it here so this one will again be joining

5:30:55 with this one this is also clear because

5:30:58 we are getting the matching report so in left

5:31:00 join all the entries from the leftmost part of the table will be getting and all

5:31:05 the matching entries from the table one

5:31:07 and table two will be getting so the first

5:31:09 two rows are quite clear because we can

5:31:11 see the we could find this one was matched

5:31:15 to it this one similarly the next entry was another one which we bought and do

5:31:20 we find one yes we are finding a one year and this one was again matched

5:31:25 with this one so this is clear coming to the third entry which is the two do

5:31:30 I find a two year yes I find a two year and that too it is present

5:31:35 two times so you can see two is present here and 2 is also present here

5:31:40 so friends what will happen What will be

5:31:43 the result so a thing which will happen is

5:31:46 each similar entry will be joined with each

5:31:50 of the similar entries which will which we

5:31:52 are getting so if you were thinking like so here true it will just be joined one

5:31:57 time with a set particular two entry it is wrong so how it works is this too

5:32:04 it'll join first with this particular 2 because

5:32:08 this is similar a similar value is being

5:32:10 found and again this particular 2 will again

5:32:13 join with this to which we are getting here so each similar entry will be joined

5:32:18 with each of the similar entries which we are

5:32:20 getting separately and that would distinguish that would

5:32:23 be processed in separate row so we'll be

5:32:26 getting separate entries for each of the joints

5:32:28 which is happening so each similar entry you

5:32:31 will be joined with each of the similar

5:32:33 entry here into the second table and for each

5:32:37 of the joins a new rows will be present into the output as you can see

5:32:43 so if this 2 is joining with these two we are getting this particular row entry

5:32:48 as you could see this is also clear how we got it again these two it will

5:32:53 find if we hire if we are having any more tools here yes we are having

5:32:57 one more two is present here so we are getting the same thing this is also clear

5:33:01 I hope the logic is quite clear it's

5:33:04 similar antique joins with each of the singular

5:33:06 entry which is present to the other table the output is into a form of a new

5:33:10 row coming to the next so this is sorted next is three so do I find

5:33:16 a three year yes I find a 3 which is present only one time so this three

5:33:22 will again join with this three and that is what we are getting into the output

5:33:26 this is also clear clear means the concept is clear I hope so now comes four

5:33:33 so do I find a 4 here no there is no 4 present but in left

5:33:37 join all the entries from the left most part of the table we get so friends here

5:33:41 that is why we'll be getting a 4 and from the table second do I find

5:33:47 a four no there is no four present so that is why this will come up

5:33:51 as a null value similarly I hope this is

5:33:56 clear I'll modulus C similarly coming to three

5:34:00 so do I find a three year yeah I can find a three here so this three

5:34:05 will again be joined with this three and we are getting you can see this entry

5:34:08 is because of that joint which is happening now do I find any more three report

5:34:13 from this single entry into the table two which is I am waiting for three no I

5:34:18 cannot find so that is what join would

5:34:20 not happen any additional joints will not happen so

5:34:23 that is why we are getting a clear so concept is clear the row entry is

5:34:27 clear how we got this coming to the most

5:34:31 interesting part of this particular joint condition which

5:34:34 is the null so friends let us assume these are some of the null values which

5:34:39 is present here now none when we're joining

5:34:43 null with something it is unequal that is pretty

5:34:47 much correct like let's say if you are joining null with a number which is four

5:34:54 it is pretty much relevant that the null

5:34:56 would the join will not happen because join only

5:34:59 happens if both the criteria matches so a is equal to B so only only then

5:35:05 the join would happen so null will not

5:35:07 match in case of this particular case but here

5:35:10 you can see I have a null present here I have again a null which is

5:35:13 better idea so ideally the output for null

5:35:17 should be something like null joining with this particular

5:35:21 and also we should have gotten null

5:35:23 and here now we are getting and similarly null

5:35:26 we are should be joined with this null and we are getting an entry here or two

5:35:31 rows entry so I would like to tell you this Logic for null is wrong what

5:35:37 I mentioned right now is is wrong this is not how the null joint works so

5:35:42 in SQL null is not equal to null that means that the joints cannot happen in any

5:35:49 case but into this particular case you can

5:35:51 see okay why astos has written two additional

5:35:54 rows for null if if that was the case in if in SQL null is not

5:36:00 equal to null then this join should not

5:36:02 have happened and we should not have water

5:36:04 in these two rows but our storage has written both of these rows how is he doing

5:36:09 this so the result which is writing is

5:36:12 wrong that means no it is not wrong because

5:36:15 one more condition is there which is from the left table we get all the entries

5:36:21 which is present irrespective of whether we are

5:36:24 finding a match result or we are not finding a match result so this is the most

5:36:28 critical thing into the left join or the joining

5:36:31 condition if you just think of so

5:36:33 that is why I explicitly mentioned null into two

5:36:38 different types you can see here I

5:36:41 have mentioned null into small caps capital letter

5:36:43 that means that no matching value was found

5:36:47 and this null value I'm getting from the first

5:36:50 table itself so you can read it something like the null which I am getting here

5:36:56 did not find a matching result from the second

5:36:58 table and that is why I am getting

5:37:01 on null value so this null is similar to you know because there was no matching

5:37:06 report found that is why I'm getting another

5:37:07 thing likewise for this particular null also I'm giving

5:37:11 a null value so friends I hope this particular

5:37:13 important concept is quite clear to you I

5:37:17 would request you please revisit these concept these are

5:37:20 most our single interview questions onto the joints

5:37:23 how does different joints internally they work internally

5:37:26 they function I have made a separate video

5:37:29 onto these particular joints how they will work

5:37:32 and what will be their results when we'll

5:37:34 be doing a right join inner join full auto join I would add the link

5:37:38 to that video into the IE link which is

5:37:41 popping out right now onto my screen or you

5:37:44 can go to my playlist and and check that video out so that it will help

5:37:48 you to clear out the concepts that you have understood or not so first of all I

5:37:54 would request you try from your end

5:37:56 and then only look out into that particular video

5:37:59 so that it will help you to know

5:38:01 that whether the concepts have been cleared or not

Study with Looplines Download Captions Watch on YouTube