以下哪种方法更有效:
单个更长的查询:
"SELECT COUNT( * ) AS num FROM ( SELECT users.UID, cnumber FROM users JOIN identity ON users.UID = identity.UID WHERE 'abc' IN (google, facebook, twitter, linkedin) ) AS userfound JOIN jobs ON userfound.cnumber = jobs.cnumber WHERE JID = 24"; if(resultfromquery == 1) //Some code here else //Some code here
将较长的查询分解为多个单表查询:
uid = "SELECT UID FROM identity WHERE 'abc' IN (google, facebook, twitter, linkedin)"; cnumber_from_usertable = "SELECT cnumber FROM users WHERE UID = 'uid'"; cnumber_from_jobtable = "SELECT cnumber FROM jobs WHERE JID = 24"; if(cnumber_from_usertable == cnumber_from_jobtable) //Some code here else //Some code here