SQL语句问题,关联查询,一对多
比如老师和学生表,一个老师对应多个学生。想查出来老师A和他对应的学生1,2,3,老师B和他对应的4,5,6.
回复讨论(解决方案)
select * from 学生表 a,教师表 b,教师学生关系表 c where a.studentid = c.studentid and b.teacherid = teacherid and b.teacherid = 你要查的老师id
表结构是怎样的?
table teacher
id name
1 A
2 B
table student
id tid
1 1
2 1
3 1
4 2
5 2
6 2
A老师的学生
select * from student where tid=1;
B老师的学生
select * from student where tid=2;
或者 select a.*,b.name from student as a left join teacher as b on a.tid = b.id order by a.tid;
老师有个ID 查询 符合这个ID 条件的所有学生...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
