一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

where clause is ambiguous

时间:2010-01-23 编辑:简简单单 来源:一聚教程网


在一次使用mysql数据库查询的时候出现错误提示 Column 'languageid' in ,这个错误in 多半是因为多表查询的时候几个表中同时出现了某个相同的列名,而在查询条件WHERE后面又没有指定是那个表,而引起的
又或者是查询结果里面有两个相同的列名,而没有指定是哪个表
使用的时候可以这样,mysql查询前面加表名可避免出现错误Column 'languageid' in
SELECT tablea.id aid table.id bid WHERE tablea.id = tableb.id

SELECT *
FROM tbl_listings
WHERE postcode = 'var1' AND catID = 'var2' AND stateID = 'var3'
ORDER BY listingName ASC

using the following variables

name: var1
default value: -1
run-time value: $_GET['postcode']

name: var2
default value: -1
run-time value: $_GET['catID']

name: var3
default value: -1
run-time value: $_GET['stateID']


I, however, want to get the category name from the category table using a join so I tried this:

 


Code:
SELECT *
FROM tbl_listings LEFT JOIN tbl_category ON tbl_listings.catID = tbl_category.catID
WHERE postcode = 'var1' AND catID = 'var2' AND stateID = 'var3'
ORDER BY listingName ASCusing the following variables

name: var1
default value: -1
run-time value: $_GET['postcode']

name: var2
default value: -1
run-time value: $_GET['catID']

name: var3
default value: -1
run-time value: $_GET['stateID']

 

This gives me an error saying: Column: 'catID' in where clause in ambiguous.


WHERE postcode = 'var1' AND tbl_listings.catID = 'var2'

OR
PHP Code:
WHERE postcode = 'var1' AND tbl_category.catID = 'var2'

热门栏目