left right inner Join 多表联查的问题(附实际例子)!
sql="select * FROM phpcms_content AS a left JOIN phpcms_attachment AS b ON 'a.contentid' = 'b.contentid' ORDER BY a.contentid DESC limit 0 1"
查询返回是:
Array
(
[contentid] =>
[catid] =>
[typeid] => 0
[areaid] => 0
[title] => 寂寞的迷途小羔羊
[style] =>
[thumb] => uploadfile/2009/0815/20090815111022437.jpg
[keywords] => 迷途 羔羊
[description] =>
[posids] => 0
[url] => suoai/w810/zhuti-2.html
[listorder] =>
[status] => 99
[userid] =>
[username] => seeyou
[inputtime] => 1250305989
[updatetime] => 1250327706
[searchid] => 2
[islink] => 0
[prefix] =>
[aid] =>
[module] =>
[field] =>
[filename] =>
[filepath] =>
[filetype] =>
[filesize] =>
[fileext] =>
[isimage] =>
[isthumb] =>
[downloads] =>
[uploadtime] =>
[uploadip] =>
)
phpcms_attachment 这个表里面的内容一个都没有值
sql="select * FROM phpcms_content AS a right JOIN phpcms_attachment AS b ON 'a.contentid' = 'b.contentid' ORDER BY a.contentid DESC limit 0 1"
查询返回的内容是:
Array
(
[contentid] => 0
[catid] => 0
[typeid] =>
[areaid] =>
[title] =>
[style] =>
[thumb] =>
[keywords] =>
[description] =>
[posids] =>
[url] =>
[listorder] => 0
[status] =>
[userid] => 1
[username] =>
[inputtime] =>
[updatetime] =>
[searchid] =>
[islink] =>
[prefix] =>
[aid] => 2
[module] => phpcms
[field] => uploadfile
[filename] => w800.thm
[filepath] => 2009/0815/20090815095533242.thm
[filetype] => application/octet-stream
[filesize] => 440320
[fileext] => thm
[isimage] => 0
[isthumb] => 0
[downloads] => 0
[uploadtime] => 1250301333
[uploadip] => 113.96.45.196
)
phpcms_content表的内容都没有值
sql="select * FROM phpcms_content AS a inner JOIN phpcms_attachment AS b ON 'a.contentid' = 'b.contentid' ORDER BY a.contentid DESC limit 0 1"
返回的内容为空.
下面是数据结构
phpcms_content
Array
(
[contentid] => 2
[catid] => 44
[typeid] => 0
[areaid] => 0
[title] => 寂寞的迷途小羔羊
[style] =>
[thumb] => uploadfile/2009/0815/20090815111022437.jpg
[keywords] => 迷途 羔羊
[description] => 寂寞的迷途小羔羊
[posids] => 0
[url] => suoai/w810/zhuti-2.html
[listorder] => 0
[status] => 99
[userid] => 1
[username] => seeyou
[inputtime] => 1250305989
[updatetime] => 1250327706
[searchid] => 2
[islink] => 0
[prefix] =>
)
phpcms_attachment
Array
(
[aid] => 7
[module] => phpcms
[catid] => 0
[contentid] => 2
[field] => thumb
[filename] => w810.jpg
[filepath] => 2009/0815/20090815111022437.jpg
[filetype] => image/pjpeg
[filesize] => 10629
[fileext] => jpg
[description] =>
[isimage] => 1
[isthumb] => 0
[downloads] => 0
[listorder] => 0
[userid] => 1
[uploadtime] => 1250305822
[uploadip] => 113.96.45.196
)
请问我如何才能联合查询到这个id 在两个表里面所有的内容,返回一个数组呢?
如果两个表可以,三个表一起查,又如何做呢?