简体   繁体   English

SQL:如何从 2 个表中选择所有记录

[英]SQL: How to select all records from 2 tables

I'm trying with SQL query to select all the projects from 1 table and from table 2 all the emails.我正在尝试使用 SQL 查询从 1 个表和表 2 中的所有电子邮件中选择所有项目。 The final result should:最终结果应该:

project_name student_email         
project 1    email 1 

This for all the records I have.这是我拥有的所有记录。 The 2 tables look like:这两个表看起来像:

Student table:学生表:

在此处输入图片说明

Projects table:项目表:

在此处输入图片说明

What I would like to know is the query to select all the project and specify also the emails associated from students table我想知道的是选择所有项目并指定与学生表关联的电子邮件的查询

The query should be:查询应该是:

Select pro.project_name, st.student_mail from student st join projects pro on (st.student_id=pro.student_id)

You can add a where at the end.您可以在最后添加一个 where。

pro.亲。 and st.和圣。 -> These 2 are Aliases, just so i don´t have to type Table´s full name. -> 这 2 个是别名,所以我不必输入表的全名。

If you want to receive data from 2 or more tables, u should use Joins.如果你想从 2 个或更多表接收数据,你应该使用连接。

For more information about "joins":有关“连接”的更多信息:

- https://www.w3schools.com/sql/sql_join.asp - https://www.w3schools.com/sql/sql_join.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM