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;

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
sql query select from two tables with where select record two tables from sql table select sql from two different tables query data from two tables sql select with two tables sql sql query selecting from 2 tables sql query select with two tables sql how to select data from two tables sql select all from 2 tables select from two db tables in one statement database "SELECT * FROM two table how to select multiple tables sql sql how to select from two tables select two tables query from two tables sql how to select two columns from different tables in sql sql get from two tables sql selet from 2 tables select into two tables sql select * from two tables sql select from two tables t query to select data from two tables in sql sql select 2 tables select from two tables select query for two tables select all from multiple tables sql selecting data from multiple tables in sql how to select two tables in sql how to select data from two different tables in sql select all data from multiple tables sql how to select 2 tables in sql select from different tables sql how to select from different tables sql sql how to select things from two tables select records from two tables sql sql two select different tables how to select values from two tables in sql how to select from multiple tables in sql select * from two table select * from 2 tables sql select values from two tables sql how to select all from multiple tables sql sql select from two table with where select different rows from two tables in sql sql select * from two tables select data from 2 tables sql sql select data from 2 different tables select all from two tables sql select rows from 2 tables sql how to make select from two tables select query from two different tables how to select from two tables how to select information from two tables in sql selecting from multiple tables sql can you select from multiple tables in sql sql query to select from two tables select data from two different tables in sql selecting from multiple tables sql using or selecting data from multiple tables sql select data from two tables in sql select from 2 different tables sql select data from two tables can you select from two different tables sql how to make a select on 2 tables in sql select from two tables access SELECT DATA FROM 2 TABLE SQL how to select values from 2 tables in sql select values from 2 tables sql sql select from multiple tables where statement AND sql select from multiple tables where statement sql select * from 2 tables select from 2 tables sql from select from 2 tables sql how to select data from two tables in sql select all from 2 tables sql select from two table select from 2 tables select two columns from different tables sql How do i Select Data From Two table in Sql sql query to select data from two tables select statement two tables from select data from two tables sql where statement select sql from two tables select data from multiple tables sql sql to select from multiple tables sql from two tables select two tables in one query how to select rows from two tables in sql selct from sql multiple tables select from two different tables sql sql select from 2 tables select two tables sql sql select from multiple tables sql select from two tables select from two tables sql how to query from two tables in sql how to select data from multiple tables in sql how to select from two tables in sql
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source