一条SQL语句的问题,求解

WBOY
Release: 2016-06-20 12:42:55
Original
848 people have browsed it

这是问答表,student_id以及teacher_id对应下面用户表的id


这是用户表



请问我如何获取问答表的同时,如何根据student_id,以及teacher_id直接获取到用户的名称,是怎样的sql语句,一条能写完吗,求解


回复讨论(解决方案)

select a.*,b.name as student_name,c.name as teacher_name 
    from 问答表 
left join 用户表 b on a.student_id=b.id 
left join 用户表 c on a.teacher_id=c.id

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template