萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mysql教程 >> where clause is ambiguous

where clause is ambiguous

where clause is ambiguous


在一次使用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'

copyright © 萬盛學電腦網 all rights reserved