Select from multiple tables returns empty result
SELECT *
FROM t开发者_开发知识库raffic,alexat,bindx,blink
WHERE traffic.web = alexat.web
AND traffic.web = bindx.web
AND traffic.web = blink.web
AND traffic.web="mysql_real_escape_string($web)"
When I search say google.com and if one or any table hasn't got any data related to google.com then the whole result returns empty. but if all table got data about google.com then it returns without any problem. how can I solve this issue? I want get result even if only one table has got data..
You need to use LEFT OUTER JOIN
.
Something like this:
SELECT *
FROM traffic LEFT OUTER JOIN alexat USING (web)
LEFT OUTER JOIN bindx USING (web)
LEFT OUTER JOIN blink USING (web)
WHERE traffic.web="mysql_real_escape_string($web)"
You need an outer join. Have a look at the various options at http://en.wikipedia.org/wiki/Join_(SQL)
精彩评论