[英]How to access data using a SQL query that references multiple tables?
I have a few tables and inserted values into them using SQL plus: 我有一些表,并使用SQL plus将值插入其中:
INSERT INTO Location(name, addr, phone)
VALUES ('Texas Branch', '4832 Deercove Drive, Dallas, TX 75208', '214-948-7102');
INSERT INTO Librarian(eid, ID, pay, Loc_name)
VALUES (2591051, 88564, 30000.00, 'Texas Branch');
INSERT INTO Stored_In(media_id, name)
VALUES (8733, 'Texas Branch');
Suppose I write a SQL query like select location = "texas branch"
, then the output should contain the librarian for the Texas branch and media_id
, the name stored_in
- in simple words, I should get all the information related to Texas branch) 假设我编写了一个类似
select location = "texas branch"
的SQL查询,那么输出应该包含Texas分支的图书管理员和media_id
(名称为stored_in
-简单来说,我应该获得与Texas分支相关的所有信息)
Can anyone please help write the SQL query? 谁能帮忙编写SQL查询吗?
Something along the lines of: 类似于以下内容:
SELECT * FROM (
Location
INNER JOIN
Librarian ON Location.name = Librarian.Loc_name
INNER JOIN
Stored_In ON Stored_In.name = Location.name
)
WHERE(
Location.name='Texas Branch'
)
Because of the SELECT *
you will get a bunch of duplicate fields and you should replace this with the proper select. 由于
SELECT *
您将获得一堆重复的字段,因此应使用适当的select替换它。
As others have said, Google JOIN
s and understand them. 正如其他人所说,Google
JOIN
并理解它们。
You need to use joins then the SQL is straightforward. 您需要使用联接,然后SQL很简单。 If that is unclear then maybe you need to do some homework.
如果不清楚,那么您可能需要做一些作业。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.