gpt4 book ai didi

mysql - 如何为我的数据库连接表

转载 作者:行者123 更新时间:2023-11-29 12:17:32 25 4
gpt4 key购买 nike

我有一个数据库,其中有两个我正在尝试加入的表。

Table1: Employee
Table2: Video_Store

这两个表都有一个视频存储 ID (VS_ID)。我希望它显示员工的名字和姓氏以及与他们关联的 VS_ID。当我运行此语句时:

select Video_Store.VS_ID, Video_Store.VS_Name, Employee.E_LName, Employee.E_FName
from Video_Store, Employee

这就是结果。每个员工只有一个 VS_ID,而不是六个。如何减少冗余?

1. 1    West Street Borg    James
2. 4 East Street Borg James
3. 5 North Tremo Borg James
4. 6 South Stree Borg James
5. 7 Elm Street Borg James
6. 8 Boston Stre Borg James
7. 1 West Street Wong Franklin
8. 4 East Street Wong Franklin
9. 5 North Tremo Wong Franklin
10. 6 South Stree Wong Franklin
11. 7 Elm Street Wong Franklin
12. 8 Boston Stre Wong Franklin
13. 1 West Street Freed Alex
14. 4 East Street Freed Alex
15 5 North Tremo Freed Alex
16. 6 South Stree Freed Alex
17. 7 Elm Street Freed Alex
18. 8 Boston Stre Freed Alex
19. 1 West Street James Jared
20. 4 East Street James Jared
21. 5 North Tremo James Jared
22. 6 South Stree James Jared
23. 7 Elm Street James Jared
24. 8 Boston Stre James Jared
25. 1 West Street Wallace Jennifer
26. 4 East Street Wallace Jennifer
27. 5 North Tremo Wallace Jennifer
28. 6 South Stree Wallace Jennifer
29. 7 Elm Street Wallace Jennifer
30. 8 Boston Stre Wallace Jennifer

最佳答案

Both of these tables have a Video store id (VS_ID). I want it to show the first and last name of the employee as well as the VS_ID they are associated with.

确实,您只是缺少指定 VS_ID 条件。

SELECTVideo_Store.VS_ID, Video_Store.VS_Name, Employee.E_LName, Employee.E_FName
FROM Video_Store
JOIN Employee ON Video_Store.VS_ID = Employee.VS_ID

由于您没有指定任何条件,因此您的查询返回两个表的笛卡尔积。

关于mysql - 如何为我的数据库连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29544214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com