What about joining in sql please🤗 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What about joining in sql please🤗

INNER , LEFT , RIGHT

5th Feb 2019, 1:57 PM
MOHAMMED MOTASIM HAMED
MOHAMMED MOTASIM HAMED - avatar
8 Answers
+ 3
JOIN is used to combine two (or more) tables, usually based on some common field. There are 3 basic join types: 1.) Inner Join: retrieve the mathematical intersection of the two sets (think of Venn diagram), so only those records which are common in both tables. Syntax (these examples are equivalent): SELECT * FROM t1, t2 WHERE t1.key = t2.key; SELECT * FROM t1 JOIN t2 ON t1.key = t2.key; SELECT * FROM t1 INNER JOIN t2 ON t1.key = t2.key; Preferred is the second solution. First syntax is not really encouraged because it mixes up the join condition into the row filtering condition (WHERE clause). Using the JOIN keyword makes your code much more readable when building large complex queries.
5th Feb 2019, 11:42 PM
Tibor Santa
Tibor Santa - avatar
+ 2
what are you meaning😅🇸🇾
5th Feb 2019, 2:05 PM
Eyad Al-Ahmar
Eyad Al-Ahmar - avatar
+ 2
You can find more examples and diagrams here. If still not clear, let me know your question. https://www.w3schools.com/sql/sql_join.asp
5th Feb 2019, 11:46 PM
Tibor Santa
Tibor Santa - avatar
+ 1
I mean if any persone know about "joining" in sql to declare and understand 😅😅😙😙
5th Feb 2019, 4:09 PM
MOHAMMED MOTASIM HAMED
MOHAMMED MOTASIM HAMED - avatar
+ 1
There are lessons in sololearn about joins. https://www.sololearn.com/learn/SQL/1866/ I wrote some recap comments under one of those I can copy here.
5th Feb 2019, 11:41 PM
Tibor Santa
Tibor Santa - avatar
+ 1
2.) Outer Join: retrieve the combined results from both tables -- this has 3 variants: - Left Outer Join: all results from first table, including matches from second. SELECT * FROM t1 LEFT JOIN t2 ON t1.key = t2.key; - Right Outer Join: matches only from first table but everything from second. SELECT * FROM t1 RIGHT JOIN t2 ON t1.key = t2.key; - Full Outer Join (not supported by MySQL): all results from both tables and the matches are combined. SELECT * FROM t1 FULL JOIN t2 ON t1.key = t2.key; OUTER keywords before JOIN are optinal. If you need results that exist only in the first table, you can use left join and filter out the matches (where key in second table is found): SELECT * FROM t1 LEFT JOIN t2 ON t1.key = t2.key WHERE t2.key IS NULL; Note: various DB engines (Oracle, MS SQL) usually have old proprietary syntax for outer joins, based on the comma syntax. These are discouraged and in newer database versions obsoleted. They make your query unportable and incompatible with future versions.
5th Feb 2019, 11:43 PM
Tibor Santa
Tibor Santa - avatar
+ 1
3.) Cross Join: the Cartesian product of the two sets, each row in t1 is combined with each row in t2, can result in large data set. There is no condition. SELECT * FROM t1 CROSS JOIN t2;
5th Feb 2019, 11:43 PM
Tibor Santa
Tibor Santa - avatar
0
I have a qn
14th Feb 2019, 2:34 PM
Japhet Jibalo