如何实现join运算符

时间:2011-09-02 10:06:41

标签: mysql sql join

我的数据库中有3个表,如下所示: -

 (1) users_registration
     - username
     - email
     - acode

 (2) vendor_registration
     - vid
     - vkey
     - btype
     - email
     - pass
     - bussname
     - regdate
     - url
     - ownerfname

 (3) vorder
     - ttime
     - vid
     - tid
     - oid
     - uid
     - amount
     - cardid

users_registration表中的用户名和vorder表中的uid是相同的。

我的代码到目前为止: -

SELECT vo.ttime,vo.vid,vo.tid,vo.oid,vo.uid,vo.amount,vo.cardid, vr.bussname 
from vorder vo 
INNER JOIN vendor_registration vr ON vo.vid=vr.vid
where uid='".$name_array[$z]."'
order by ttime desc";

应用此代码后,我的页面就像这样 ![在此输入图像说明] [1]

实际上,我想在vid的位置显示我的bussname

 e451ffc8-db29-4c08-ac67-0177aec6e2ab as shown in image vendorname,

1 个答案:

答案 0 :(得分:1)

    SELECT vo.ttime, vr.bussname, vo.tid, vo.oid, vo.uid, vo.amount, vo.cardid
      FROM vorder vo 
INNER JOIN vendor_registration vr 
        ON vo.vid = vr.vid 
     WHERE uid = '".$name_array[$z]."' 
  ORDER BY ttime DESC