where clause is ambiguous

來源:互聯網
上載者:User


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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.