Questions tagged [mysql-error-1052]

Error 1052 - "Column '%s' in field list is ambiguous". This error appears because there are more than one identically named columns referenced in the query.

Error 1052 - "Column '%s' in field list is ambiguous".
This error appears because there are more than one identically named columns referenced in the query. IE:

SELECT column,
       column
  FROM TABLE_1,
       TABLE_2
 WHERE ...

The solution is to prefix the table or the table alias the respective column is from.

Using the table name

SELECT TABLE_1.column,
       TABLE_2.column
  FROM TABLE_1,
       TABLE_2
 WHERE ...

Using the table alias

SELECT t1.column,
       t2.column
  FROM TABLE_1 t1,
       TABLE_2 t2
 WHERE ...

The AS is optional for table aliases.

Caveat

You'll probably want to provide a column alias in order to know which value you retrieve:

SELECT t1.column AS T1_column,
       t2.column AS T2_column
  FROM TABLE_1 t1,
       TABLE_2 t2
 WHERE ...
46 questions
136
votes
8 answers

1052: Column 'id' in field list is ambiguous

I have 2 tables. tbl_names and tbl_section which has both the id field in them. How do I go about selecting the id field, because I always get this error: 1052: Column 'id' in field list is ambiguous Here's my query: SELECT id, name, section FROM…
Wern Ancheta
  • 22,397
  • 38
  • 100
  • 139
84
votes
6 answers

MySQL - Selecting data from multiple tables all with same structure but different data

Ok, here is my dilemma I have a database set up with about 5 tables all with the exact same data structure. The data is separated in this manner for localization purposes and to split up a total of about 4.5 million records. A majority of the time…
Jayrox
  • 4,335
  • 4
  • 40
  • 43
76
votes
11 answers

How to resolve ambiguous column names when retrieving results?

I have two tables in my database: NEWS table with columns: id - the news id user - the user id of the author) USERS table with columns: id - the user id I want to execute this SQL: SELECT * FROM news JOIN users ON news.user = user.id When I…
Dan
  • 9,912
  • 18
  • 49
  • 70
19
votes
4 answers

MySQL 'user_id' in where clause is ambiguous problem

How can I correct the problem I keep getting from the code below which states 'user_id' in where clause is ambiguous. Thanks for the help in advance. Here is the mysql table. SELECT user.*, user_info.* FROM user INNER JOIN user_info ON…
HoMe
  • 193
  • 1
  • 1
  • 4
15
votes
1 answer

Column 'id' in where clause is ambiguous

I get this error and I can't figure out why? Error Number: 1052 Column 'id' in where clause is ambiguous SELECT `leads`.*, `customers`.`id` AS customers_id, `customers`.`name` AS customers_name, `customers`.`company` AS…
Casperlarsen
  • 171
  • 1
  • 3
  • 10
11
votes
3 answers

Column in where clause is ambiguous - What does that mean?

I've come across this error in MySQL for the join clause but I'm fairly new to the JOIN argument and I'm not sure what this means. Can anyone help? Column 'id' in where clause is ambiguous SELECT * FROM (`venues`) JOIN `venues_meta` ON…
Ben
  • 4,301
  • 6
  • 37
  • 61
5
votes
1 answer

Laravel relationship Column 'id' in where clause is ambiguous

I have courses and subscription types. I want to get all the courses that has a given subscription type. My attempt: $courses=Course::wherehas('subscriptionType',function ($q) { return $q->where('id','1'); })->get(); But…
4
votes
1 answer

Ambiguous column in MySQL/Rails find method

I'm getting this error Mysql::Error: Column 'id' in field list is ambiguous when using a find method like such: self.prompts.find(:all, :select => 'id') The models are being called using a has_many :through association, so MySQL complains that…
John
  • 477
  • 5
  • 13
4
votes
1 answer

Mysql error: violation: 1052 Column 'created_at' in where clause is ambiguous'

I am getting the issue: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous but the table sales_flat_order_grid have created_at Column SELECT DISTINCT main_table.*, blacklist.entity_id AS marked…
Amit Bera
  • 7,581
  • 7
  • 31
  • 57
4
votes
3 answers

MySQL Need help constructing query: join multiple tables into single row

Forgive me if this question has been asked and answered, I've searched and found a few that look similar but I'm too much of a novice with SQL to adapt them to my needs. Also forgive me if I don't use the correct terminology, I know it can be…
Jed Daniels
  • 24,376
  • 5
  • 24
  • 24
4
votes
2 answers

Error Code: 1052 Column 'admin_id' in field list is ambiguous

Hi I have tried to create a time sheet view in my database but I'm having trouble with the admin_id column. I'm reusing this code from another assignment which works so I'm confused t why it doesn't work. Please Help me!!! Select Statement SELECT…
user2528515
4
votes
2 answers

1052 - Column 'typeid' in field list is ambiguous

select id,pubdate, typeid,aid,jobname,jobdepart,jobplace,jobnumber,jobcontact from archives right join jobrt on id=aid where typeid=19 1, table archives have fileds: id,pubdate,typeid... 2, table jobrt have…
stackoverflow002
  • 329
  • 1
  • 3
  • 10
3
votes
4 answers

Column 'id_f' in where clause is ambiguous

i have a join query using 3 table but i get this problem Column 'id_f' in where clause is ambiguous $id_f=$_GET['id_f']; $query="SELECT *, s.name AS van, st.name AS naar, p.titl, p.vname FROM p1_users, f_confirm AS v INNER JOIN s_steden AS s ON…
mary
  • 149
  • 1
  • 5
  • 10
3
votes
2 answers

incremental update in insert ... on duplicate key

Is there any way to do an incremental update in an on duplicate key update insert in mysql? Example w/ error: insert into blah (user_id, prefix, email_id, field, source) select user_id, substring(name, 1, 3), contact_email_id, 2, source from…
ʞɔıu
  • 47,148
  • 35
  • 106
  • 149
3
votes
3 answers

MySQL: "Column 'column_name' in where clause is ambiguous"

I JOIN 2 tables for example table_A +---------+-----------+-----------+ | user_id | ticket_id | user_name | +---------+-----------+-----------+ table_B +-----------+-------------+ | ticket_id | ticket_name | +-----------+-------------+ If I run…
Jacco
  • 23,534
  • 17
  • 88
  • 105
1
2 3 4