Showing posts with label Learn SQL. Show all posts
Showing posts with label Learn SQL. Show all posts

Tuesday, January 30, 2024

Left Join

 What is Left Join?

The SQL left join performs an inner join first with the matching values from the right table and it returns all the values from the left table even if there is no matching join value, it will return a corresponding NULL based on a matching row.















Example
























Table_1

create table Table_1 (A varchar);

Insert into Table_1 (A)

values ('x'),('x'),('x'),('0'),('0'),('z');

 

select * from Table_1;



Table_2

create table Table_2 (A varchar);

Insert into Table_2 (A)

values ('y'),('y'),('0'),('x'),('x');

 

select * from Table_2;



Syntax for Left Join

SELECT table1.column1, table1.column2, table2.column1,....

FROM table1

LEFT JOIN table2

ON table1.matching_column = table2.matching_column;


--left join query--

select *from Table_1 T1

left join Table_2 T2

on T1.A=T2.A;


Friday, January 26, 2024

Create table in SQL

Create Table in postgre SQL

It is always advisable to make small tables in SQL to practice queries. Below is an explanation of How to make a simple table in SQL.


CREATE command is used to create a new table in the database


Syntax: create table TABLE_NAME (COLUMN_NAME data type[,....]);

INSERT  command is used to create a new table in the database

Syntax: insert into TABLE_NAME (col1, col2, col3,.... col N) values (value1, value2, value3,... valueN);


Example table ;





QUERY ; 

  Syntax:

create table Table_1 (A varchar); Insert into Table_1 (A)

values ('x'),('x'),('y'),('z');

select * from Table_1;