1

I have two table :

news:

|id|title|image|timestamp|....

tags:

|id|books_id|...

for result:

("SELECT id,title,front_thumbs,short_desc,timestamp,counter,author,
  FROM " . NEWS . " LEFT JOIN " . TAGS . " ON " NEWS . ".id = " . TAGS . ".content_id WHERE 
" . TAGS . ".tags_id = ? AND approved = 1 ORDER BY timestamp DESC LIMIT 10", $id)

but I see this error:

Error: Column 'id' in field list is ambiguous 

how do fix this error?

P.O.P
  • 101
  • 1
  • 1
  • 6
  • Which `id` do you want? `news.id` OR `tags.id`? You can have either OR both, you just need to add the table name - `SELECT news.id, ...` or `SELECT tags.id, ...` or `SELECT news.id, tags.id, ...` – Sean Sep 12 '15 at 06:06
  • possible duplicate of [1052: Column 'id' in field list is ambiguous](http://stackoverflow.com/questions/6638520/1052-column-id-in-field-list-is-ambiguous) – Sean Sep 12 '15 at 06:25

2 Answers2

0

You need alias. Yuo have 2 tables both with column id. In your select you request id without specifying which of them you need.

You need to specify table here (before id):

... ("SELECT id,title,front_thumbs,short ...

Bogdan Bogdanov
  • 1,707
  • 2
  • 20
  • 31
0

When both tables have same field name it gets ambiguous and to solve this use SELECTNEWS.id or TAGS.id which table's id you are using:

"SELECT NEWS.id,title,front_thumbs,short_desc,timestamp,counter,author,
FROM " . NEWS . " LEFT JOIN " . TAGS . " ON " NEWS . ".id = " . TAGS .    ".content_id WHERE 
" . TAGS . ".tags_id = ? AND approved = 1 ORDER BY timestamp DESC LIMIT 10", $id)
Insane Skull
  • 9,220
  • 9
  • 44
  • 63