[SQL] Query using Data from 2 Tables

  • Thread starter Thread starter WWGD
  • Start date Start date
  • Tags Tags
    Data Sql
Click For Summary

Discussion Overview

The discussion revolves around constructing a SQL query that retrieves data from two related tables, specifically focusing on the salary of teachers who teach French during a specified time. The conversation explores the mechanics of joining tables in SQL.

Discussion Character

  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • One participant inquires about the necessity of joining two tables, T_1 (containing teaching subjects) and T_2 (containing class schedules), to obtain specific data.
  • Another participant confirms that a join is required and provides an example of a LEFT JOIN query, noting the implications of NULL values in the results.
  • A later participant questions whether the join table is physically created or exists only in memory during query execution.
  • Subsequent responses clarify that the join table is not created permanently but is generated in memory for the duration of the query.

Areas of Agreement / Disagreement

Participants generally agree on the mechanics of performing a join in SQL and the nature of the join table, with no significant disagreements noted.

Contextual Notes

Participants mention the potential impact of NULL values on the results of the join, indicating that the behavior of the query may depend on the data present in the tables.

WWGD
Science Advisor
Homework Helper
Messages
7,804
Reaction score
13,111
Hi, say I am doing a query for which I need data from two tables,

on, say the salary of those who teach French from 2-to-3 P.M, and one table T_1

contains the teaching subject and another table T_2 contains the class schedule/hours.

Say these two tables are related.

Do we then do a query on the join of the tables T_1 with T_2 ?
 
Technology news on Phys.org
Yes you simply do a join.
It depends on which table may contain NULL values.
Lets say :

SELECT *
FROM T_1
LEFT JOIN T_2
ON T_1.subject = T_2.subject;

This query tells to join the left table (T_1) with the right table (T_2) . The result will be NULL on the right side if there is no match.
 
I see, thanks, but the join table is not actually created, is it, it just lives in memory when the query is being computed, right?
 
Sorry for the late reply,
Yes, the table won't be created
 
Thank you, ZLB.
 

Similar threads

  • · Replies 51 ·
2
Replies
51
Views
6K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
5
Views
7K
  • · Replies 9 ·
Replies
9
Views
2K