資料表activity 中有欄位 ac_id ac_title openid 等欄位
資料表 apply 中有ap_id ac_id(既activity表中的ac_id) openid 等欄位
現在需要先查出apply中有 符合使用者的openid的欄位 然後 再查詢出 apply表中ac_id等於activity表中ac_id的資料集
query("select * from activity,apply where apply.ac_id=activity.ac_id order by ap_id desc");
這樣的語句只能查詢出 apply表中ac_id等於activity表中ac_id的資料集 但是不知道怎麼查出 apply中openid等於使用者openid的資料 所以 業務開發的時候不能區分開始那個使用者的 跪求大神提出解決方案 小弟是新手
回複內容:
資料表activity 中有欄位 ac_id ac_title openid 等欄位
資料表 apply 中有ap_id ac_id(既activity表中的ac_id) openid 等欄位
現在需要先查出apply中有 符合使用者的openid的欄位 然後 再查詢出 apply表中ac_id等於activity表中ac_id的資料集
query("select * from activity,apply where apply.ac_id=activity.ac_id order by ap_id desc");
這樣的語句只能查詢出 apply表中ac_id等於activity表中ac_id的資料集 但是不知道怎麼查出 apply中openid等於使用者openid的資料 所以 業務開發的時候不能區分開始那個使用者的 跪求大神提出解決方案 小弟是新手
只要在 sql 中加上 openid 的條件不就行了,就是如下加上 and openid='xxx'
select * from activity,apply where apply.ac_id=activity.ac_id and apply.openid='xxx' order by ap_id desc
假設目前要搜尋的使用者的openid = 2,你的意思是:
1.從資料表activity中搜出openid == 2的資料,作為資料集1.
2.對於資料集1中的資料,在資料表apply中查出apply.ac_id == 資料集1.ac_id 的資料?
左串連怎麼樣親
select * from activity as ac left join apply as ap on ac.ac_id = ap.ac_id where openid = "xxxxx"