使用php在mysql中的两个数据库中的多个表

时间:2014-10-08 04:20:49

标签: php mysql

我在Mysql db中有2个表,表1

serial      Remark   
-------------------
1           programming in c++ 
2           OOPS using java    

和表2

Name      date         code    serial
-------------------------------------
Jack     2014-10-07    c++        1
Jill     2014-10-07    c++        1 
Moos     2014-10-07    c++        1
Jack     2014-10-08    java       2
Jill     2014-10-08    java       2

我想在HTML中使用php生成多个表,

1.使用c ++编程的学生

Name      date       
-------------------
Jack     2014-10-07
Jill     2014-10-07
Moos     2014-10-07

2.使用java的OOPS中的学生

Name      date       
-------------------
Jack     2014-10-08
Jill     2014-10-08

有人可以建议查询吗?

1 个答案:

答案 0 :(得分:0)

查询案例1:

SELECT name, date from table2 inner join table1 on table2.serial = table1.serial where Remark='programming in c++'

查询案例2:

SELECT name, date from table2 inner join table1 on table2.serial = table1.serial where Remark='OOPS using java'

,或者

另一种方式:

查询案例1:

SELECT name, date from table2, table1 where table2.serial = table1.serial and Remark='programming in c++'

查询案例2:

SELECT name, date from table2, table1 where table2.serial = table1.serial and Remark='OOPS using java'