how to select data from two tables in sql code example
Example 1: how to select from two tables in sql
SELECT t1.name, t2.salary FROM t1 JOIN t2 on t1.id = t2.id;
SELECT t1.*, t2.salary FROM t1 JOIN t2 on t1.id = t2.id;
SELECT t1.name, t2.salary FROM t1 LEFT OUTER JOIN t2 on t1.id = t2.id;
SELECT emp_name AS name from employees
UNION
SELECT cust_name AS name from customers;
SELECT emp_name AS name from employees
UNION ALL
SELECT cust_name AS name from customers;
Example 2: how to join tables in sql
JOINING 2 Tables in sql
SELECT X.Column_Name , Y.Column_Name2
FROM TABLES1_NAME X
INNER JOIN TABLES2_NAME Y ON X.Primary_key = Y.Foreign_key;
SELECT E.FIRST_NAME , J.JOB_TITLE
FROM EMPLOYEES E
INNER JOIN JOBS J ON J.JOB_ID = E.JOB_ID;
Example 3: sql combine results from two tables
SELECT *
FROM tutorial.crunchbase_investments_part1
UNION
SELECT *
FROM tutorial.crunchbase_investments_part2