Answers for "how to select data from two tables in sql"

SQL
26

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;


--FOR EXAMPLE
--GET THE FIRST_NAME AND JOB_TITLE
--USE EMPLOYEES AND JOBS TABLE
--THE RELATIONSHIP IS JOB_ID

SELECT E.FIRST_NAME , J.JOB_TITLE
FROM EMPLOYEES E
INNER JOIN JOBS J ON J.JOB_ID = E.JOB_ID;
Posted by: Guest on December-01-2020
1

SQL | SELECT data from Multiple Tables

SELECT tablenmae1.colunmname, tablename2.columnnmae    
FROM tablenmae1  
JOIN tablename2  
ON tablenmae1.colunmnam = tablename2.columnnmae
ORDER BY columnname;
Posted by: Guest on June-25-2021
1

how to select from two tables in sql

-- With JOIN
-- No row if id does not exist in t2
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;
-- A row with a NULL salary is returned if id does not exist in t2
SELECT t1.name, t2.salary FROM t1 LEFT OUTER JOIN t2 on t1.id = t2.id;

-- With UNION: distinct values
SELECT emp_name AS name from employees
UNION
SELECT cust_name AS name from customers;

-- With UNION ALL: keeps duplicates (faster)
SELECT emp_name AS name from employees
UNION ALL
SELECT cust_name AS name from customers;
Posted by: Guest on April-23-2021
0

sql combine results from two tables

SELECT *
  FROM tutorial.crunchbase_investments_part1

 UNION

 SELECT *
   FROM tutorial.crunchbase_investments_part2
Posted by: Guest on January-04-2021

Code answers related to "how to select data from two tables in sql"

Code answers related to "SQL"

Browse Popular Code Answers by Language