程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> where clause is ambiguous

where clause is ambiguous

編輯:MySQL綜合教程

where clause is ambiguous

where clause is ambiguous
在一次使用mysql數據庫查詢的時候出現錯誤提示 Column 'languageid' in where clause is ambiguous,這個錯誤in where clause is ambiguous多半是因為多表查詢的時候幾個表中同時出現了某個相同的列名,而在查詢條件WHERE後面又沒有指定是那個表,而引起的
又或者是查詢結果裡面有兩個相同的列名,而沒有指定是哪個表
使用的時候可以這樣,mysql查詢前面加表名可避免出現錯誤Column 'languageid' in where clause is ambiguous
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'

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved