Posts

Showing posts with the label sql operators

flow of co related sub query

Image

What is co related sub query | SQL Tutorial 17

Image
What is co related sub query Co-related sub query  - if a sub query depends on output generated by outer query. Use-     Get Department details which is having no employee right now.    Get Product details which sold to any single Customer. Co-related sub query Uses two operator EXISTS- get object details   if having something then use EXISTS operator between Inner and outer query. NOT EXISTS- get object details   if not having something then use NOT   EXISTS  operator between Inner and outer query. Syntax - select ..... from table_name where EXISTS/NOT EXISTS ( select..... from table_name2 where table1.pkcolum = table2fkcolum  ); Example get department details where having at least 1 employee select d.* from dept d where EXISTS (select e.empno from emp e where e.deptno =  d.deptno); get department details where not having at least 1 employee select d.* from dept d where NOT EXISTS (select e.empno from emp e where e.deptno =  d.deptno);

What is sub query | SQL Tutorial 16

What is sub query Sub query is a query with in other query is known is Sub query Use if you want to get data from table1 by using value form table2 we will go for subquery not for joins. syntax. select * from table_name where....(select * from table_name where...(select * from table_name)...)... // Inner most query execute first Type of Sub Query Single row sub query - the sub query which is returning only one output value. example- get department name of employee 708. select dname from department where deptno = (select deptno from employee where empno=708) example-  get department detailsof employee 708. select * from department where deptno = (select deptno from employee where empno=708) Multi row sub query - the sub query which is returning more than one output value. example-  get department detailsof employee 708.709 select dname from department where dept_no IN (select deptno from employee where empno IN( 708, 709)); If we want

What is Data Integrity Constraints | SQL Tutorial 15

What is Data Integrity Constraints Data Integrity means apply some business rules on data fields . for Example-  Employee id must be unique and not null. Employee salary should not be zero etc. Employee Table e_id             e_name             e_sal        e_designation                        100             Rahul                25000       software developer          // (valid record) 0                 duke                30000         manager            // (invalid because E_id must be greater than 0) 101             Shweta            0                Designer           // (invalid because E_sal must be greater than 0)        So this are basic standard that we must have to Follow. so we have constraints for avoiding invalid insertion of invalid record. Types of Data Integrity Constraints- Keys Constraints Unique not null primary key Domain constraints Check Referential Integrity Constraints Foreign Key Unique Key constraints - its

What are joins | SQL Tutorial 14

What are Joins Joins are used when we have to fetch data from multiple table with multiple conditions on column. we can also do this by Set Operators but there are a limitation set operator always work on single column and single column data. Example- we want to display name of employee and department of employee. so we have to fetch data from employee table and department table . Types of JOINS- Cross joins/cartesian product. Equi joins/Inner joins. Self joins outer joins. What is cross join or cartesian product cross join concept is similar to cartesian product in mathematics. suppose we have to tables with this data. table_a = {x, y, z}; table_b = {10, 20}; if we apply cross join here then we will get data like this. table_a x table_b = {(x, 10), (x, 20), (y, 10), (y, 20), (z, 10), (z, 20)} What is Equi join if we want to get only valid combination of records then we use Equi joins because in cross join we are getting all combination of data. sup

What is Logical Operator | SQL Tutorial 13

What is Logical Operator AND vs OR Logical operators are used to check certain condition or multiple condition. . For Example- If we want to check two or more than two condition in a single query and all condition must be true then we use - AND OPERATOR If we want to check two or more than two condition in a single query and any one condition will be true then we use -  OR OPERATOR AND ____ if we are looking for employee whose is manager and salary is greater than 50000. means here are two condition employee job is manager and salary is greater than 50000 Select * from employee where job="manager" AND salary>=50000; if we are looking for employee whose is manager and salary is greater than 50000 and city is indore. means here are two condition  employee job is manager  and  salary is greater than 50000 and city is indore Select * from employee where job="manager" AND salary>=50000 AND city="indore"; // it wil

What is Negation Operator | SQL Tutorial 12

What is Negation Operator NOT LIKE VS NOT BETWEEN VS NOT IN VS IS NOT NULL Negation Operator NOT BETWEEN, IS NOT NULL, NOT LIKE,NOT IN these operators are just opposite of special Operator. For Example- if we want to display salary not greater than 2000 and not less than 10000 use- BETWEEN if we want to display all employee whose surname is not null use- IS NULL if we want to display all employee whose firstname is not Rahul use- LIKE if we want to display all customer who are not in MUMBAI and Channai use- IN (Specific list) NOT BETWEEN _________ if we dont want record within a range then we use Between operator example if want all employee details whose salary is not between 5000 to 10000. Select * from employee where salary NOT BETWEEN '5000' AND '10000'; NOT IN __ if we dont want to display record with specific list. Example- List of employee whose salary is not 10000, 50000, 70000. select * from employee where salary NOT IN(

What is Special Operator | SQL Tutorial 11

What is Special Operator LIKE VS BETWEEN VS IN VS IS NULL Special Operator BETWEEN, IS NULL, LIKE,IN these operators are used when we display record with specific range, limit, or any specific record. For Example- if we want to display salary greater than 2000 and less than 10000 use- BETWEEN if we want to display all employee whose surname is null use- IS NULL if we want to display all employee whose firstname is Rahul use- LIKE if we want to display all customer who are MUMBAI and Channai use- IN (Specific list) BETWEEN _________ if we want record within a range then we use Between operator example if want all employee details whose salary between 5000 to 10000. Select * from employee where salary BETWEEN '5000' AND '10000'; IN __ if we want to display record with specific list. Example- List of employee whose salary is 10000, 50000, 70000. select * from employee where salary IN(10000, 50000, 70000); IS NULL _______ sel

What is Relational Operator | SQL Tutorial 10

What is Relational Operator When we have to fetch record within some condition then we use Relational Operator. for example Highest paid employee, number of employee whose salary is greater than 20000. LIKE: select * from employee where sal>20000;   //it will return all employee whose salary is greater than 20000.

What is Arithmetic Operator | SQL Tutorial 9

What is Arithmetic Operator Arithmetic Operator's are used to perform Arithmetic operation like +, -, *, /. For Example sum of salary, average salary etc. select 100+200 from student; // yes you can specify any table name here but we are printing more record means output 300 will be printed total number of records present in the table like:   100+200 //is the output title ------------- 300 300 300 .. and so on until visit all row of table Best way to do this select 100+200 from DUAl; //dual is a predefined table 100+200 ________    300 Another Example: _______________ Display 10% of current salary: select sal, (0.10*sal) "10 % of salary" from employee;

What is operators is sql | SQL Tutorial 8

What is operators is sql  The symbols which are used to perform logical and mathematical operations in SQL are called SQL operators. There are three types of Operators used in SQL. Basically when we have to perform any operation to fetch our Desired output then we use Operators. for example- sum of salary, average salary, highest paid employee etc. Types of Operators- Arithmetic Operators - Perform =, -, *, /,  % Relational Operators - ==, <=, >= , > , <  Special Operators - To Get Range, List, Null- Use BETWEEN, IN, IS NULL, LIKE  Negation Operators - its Reverse of Special Operators- NOT BETWEEn, NOT IN, NOL NULL, NOT LIKE. Logical Operators -  To Specify condition and selection is OR, AND