select * from tablename1 as t1 inner/left/right join table2 as t2 on(t1.col2=t2.col2) inner/left/right join table3 as t3 on (t2.col2=t3.col2) where ...limit $records offset $offset 大体就是这样,你仔细组织一下。:)
to 飞雪恨水: 没有明白你的意思? 难道是:“3个表存的纪录要按条件重新排序分页显示”? 也就是每条记录还是只有col_1,col_2,col_3这3个字段?呵呵,如果不是这个情况,应该不会存在什么麻烦吧?
有3个表 字段完全相同 table1 : col_1,col_2,col3 table2 : col_1,col_2,col3 table3 : col_1,col_2,col3现在要做一个组合查询,假如通过字段col_2查询 要把这3个表里的数据分页显示出来相对比较简单(为了使其具有兼容性使用如下sql语句)select table1.col_1 as t1c1,table1.col_2 as t1c2,table1.col_3 as t1c3,table2.col_1 as t2c1,table2.col_2 as t2c2,table2.col_3 as t2c3,table3.col_1 as t3c1,table3.col_2 as t3c2,table3.col_3 as t3c3 where table1.col_1 = table2.col_1另外关于分页最好使用指针mysql_data_seek()和mysql_num_rows()
你要计算什么呢?
而我要的是
col_1,col_2,col_3
col_1,col_2,col_3
col_1,col_2,col_3
UNION
select col_1,col_2,col3 from table2
UNION
select col_1,col_2,col3 from table3
大体就是这样,你仔细组织一下。:)
没有明白你的意思?
难道是:“3个表存的纪录要按条件重新排序分页显示”?
也就是每条记录还是只有col_1,col_2,col_3这3个字段?呵呵,如果不是这个情况,应该不会存在什么麻烦吧?
table1 : col_1,col_2,col3
table2 : col_1,col_2,col3
table3 : col_1,col_2,col3现在要做一个组合查询,假如通过字段col_2查询
要把这3个表里的数据分页显示出来相对比较简单(为了使其具有兼容性使用如下sql语句)select table1.col_1 as t1c1,table1.col_2 as t1c2,table1.col_3 as t1c3,table2.col_1 as t2c1,table2.col_2 as t2c2,table2.col_3 as t2c3,table3.col_1 as t3c1,table3.col_2 as t3c2,table3.col_3 as t3c3 where table1.col_1 = table2.col_1另外关于分页最好使用指针mysql_data_seek()和mysql_num_rows()