SELECT columns
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
SELECT Customers.customer_id, Customers.first_name, Orders.amount
FROM Customers
LEFT JOIN Orders
ON Customers.customer_id = Orders.customer;
SELECT
pka,
c1,
pkb,
c2
FROM
A
LEFT JOIN B ON pka = fka;
Code language: SQL (Structured Query Language) (sql)
/* https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-left-join/ */
#LEFT JOIN: Return all rows from the left table, even if there are no matches in the right
#table
syntax->SELECT column_name(s)
FROM table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
////example/////
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
FROM Persons
LEFT JOIN Orders
ON Persons.P_Id=Orders.P_Id
ORDER BY Persons.LastName
SELECT *
FROM Table_A A
LEFT JOIN Table_B B
ON A.col = B.col;
RIGHT JOIN: Matching part from both
table and unmatching part from right table.
SELECT table1.column1, table2.column2...
FROM table1
RIGHT JOIN table2
ON table1.common_field = table2.common_field;
Matching part from both table and unmatching part from left table.
123SELECT columns FROM table_A LEFT JOIN table_B ON join_conditionsXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
You need a first lookup for the values that exist in table1, so make a map using an object:
var maps = {};
for (var i = 0; i < table1.length; i++) {
maps[table1[i].attr4] = 1;
}
Then you can loop throught the items in table2 and filter them:
var result = [];
for (i = 0; i < table2.length; i++) {
if (!(table2[i].attr3 in map)) {
result.push(table2[i]);
}
}
SQL> SELECT ID, NAME, AMOUNT, DATE
FROM CUSTOMERS
LEFT JOIN ORDERS
ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;