Mar 28 2024 12:53 PM
I was given the following question on basic SQL. Can someone please help me understand this query?
SQL CONCEPT 1 Please write the result for the following query Table1 name 1.
A 2. B 3. C Table2 name 1. B 2. C 3. D Select t1.name, t2.name FROM Table1 t1 INNER JOIN Table2 t2 ON t1.name = t2.name
Apr 01 2024 10:44 PM
Apr 02 2024 04:28 AM
@JJevans It appears that your homework was formatted slightly differently to the question you posted here.
I would assume something like this:
SQL CONCEPT 1
Please write the result for the following query
Table1
name | |
1 | A |
2 | B |
3 | C |
Table2
name | |
1 | B |
2 | C |
3 | D |
Query:
Select t1.name, t2.name FROM Table1 t1 INNER JOIN Table2 t2 ON t1.name = t2.name
To answer:
"Select t1.name, t2.name" is the columns we want to receive.
"FROM Table1 t1 INNER JOIN Table2 t2" means we want a combination of the values from Table1 and Table2, using the shorthand t1 and t2 to refer to the tables
"ON t1.name = t2.name" means we combine rows where the name value is equal in both tables, and drop all other values.
This gives the following result table:
(key) | t1.name | t2.name |
1 | B | B |
2 | C | C |
Apr 02 2024 12:54 PM
@SivertSolemWow thank you so much for your insight. Much clearer now.