如何选择内部连接的区别?

时间:2014-05-29 07:54:59

标签: php mysql codeigniter

可以帮助我,我有一些关于查询选择distinct的问题,:

我的表

table_pemesan 
id_pms

table_pesan
no_psn
id_pms

table_dpesan
no_psn

我的查询mysql

select pm.id_pms,   
       pm.nama, 
       pm.date_create,
       ps.no_psn,
       ps.status, 
       dps.no_dpsn            
FROM  pemesan as pm
INNER JOIN pesan ps on ps.id_pms=pm.id_pms 
INNER JOIN dpesan dps on dps.no_psn=ps.no_psn 
ORDER BY pm.id_pms ASC 

//输出

Array
(
    [0] => Array
        (
            [id_pms] => 1
            [nama] => Isnan
            [date_create] => 2014-05-28 23:54:54
            [no_psn] => 1
            [status] => sedang diproses
            [no_dpsn] => 1
        )

    [1] => Array
        (
            [id_pms] => 1
            [nama] => Isnan
            [date_create] => 2014-05-28 23:54:54
            [no_psn] => 1
            [status] => sedang diproses
            [no_dpsn] => 2
        )

)

数组索引0& 1相同的数据,我的问题如何区分查询?谢谢b4,抱歉我的英语不好......

1 个答案:

答案 0 :(得分:0)

尝试使用此查询: -

SELECT DISTINCT pm.id_pms, pm.nama, pm.date_create, ps.no_psn, ps.status, dps.no_dpsn
FROM  pemesan as pm
INNER JOIN pesan ps on ps.id_pms=pm.id_pms 
INNER JOIN dpesan dps on dps.no_psn=ps.no_psn 
ORDER BY pm.id_pms ASC