mysql-error-1052

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

泪湿孤枕 提交于 2019-12-30 09:58:20
问题 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 annoying when someone asks a question and they don't even know enough to be able to ask for what they need. <2nd EDIT Mar22:> Ok, I didn't understand what the source data actually looked like, and that is why I couldn't get what I wanted. Thanks to

1052: Column 'id' in field list is ambiguous

我与影子孤独终老i 提交于 2019-12-16 19:57:07
问题 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 tbl_names, tbl_section WHERE tbl_names.id = tbl_section.id I could just select all the fields and avoid the error. But that would be a waste in performance. What should I do? 回答1: SQL supports qualifying a column by prefixing the reference with

1052: Column 'id' in field list is ambiguous

折月煮酒 提交于 2019-12-16 19:57:03
问题 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 tbl_names, tbl_section WHERE tbl_names.id = tbl_section.id I could just select all the fields and avoid the error. But that would be a waste in performance. What should I do? 回答1: SQL supports qualifying a column by prefixing the reference with

Ambiguous column in MySQL/Rails find method

自古美人都是妖i 提交于 2019-12-10 08:43:59
问题 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 there are multiple 'id' columns, since all 3 tables being used have an 'id' column. I looked this up and understand what is going wrong on the SQL end, but don't know how to resolve it in the ActiveRecord find method, and I'm not confident in my SQL

Ambiguous column in MySQL/Rails find method

若如初见. 提交于 2019-12-05 14:09:59
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 there are multiple 'id' columns, since all 3 tables being used have an 'id' column. I looked this up and understand what is going wrong on the SQL end, but don't know how to resolve it in the ActiveRecord find method, and I'm not confident in my SQL abilities to try rolling my own SQL query. Is there a way to massage the find method into something that

MySQL: “Column 'column_name' in where clause is ambiguous”

巧了我就是萌 提交于 2019-12-04 04:38:27
问题 I JOIN 2 tables for example table_A +---------+-----------+-----------+ | user_id | ticket_id | user_name | +---------+-----------+-----------+ table_B +-----------+-------------+ | ticket_id | ticket_name | +-----------+-------------+ If I run the following query: SELECT table_A.user_id , table_A.user_name , table_B.ticket_name FROM table_A LEFT JOIN table_B ON table_B.ticket_id = table_A.ticket_id WHERE ticket_id = '1'; On the live server we get the error: " Column 'ticket_id' in where

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

风流意气都作罢 提交于 2019-12-01 03:15:43
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 `venues_meta`.`venue_id` = `venues`.`id` WHERE `id` = '12' You need to fully qualify id because venues and venues_meta both have a column called id . I think you want: SELECT * FROM `venues` v, `venues_meta` m where v.venue_id = m.id AND m.id = '12' (but be sure it's v.venue_id you want and not v.id) Try this Code SELECT v.* FROM `venues` AS `v` INNER JOIN

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

我与影子孤独终老i 提交于 2019-11-28 03:28:04
问题 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 `venues_meta`.`venue_id` = `venues`.`id` WHERE `id` = '12' 回答1: You need to fully qualify id because venues and venues_meta both have a column called id . 回答2: I think you want: SELECT * FROM `venues` v, `venues_meta` m where v.venue_id = m.id AND m.id = '12'

MySQL 'user_id' in where clause is ambiguous problem

时间秒杀一切 提交于 2019-11-27 16:00:21
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 user.user_id = user_info.user_id WHERE user_id='$user_id' You simply need to specify which user_id to use, since both the user_info and user table have a field called user_id : ... WHERE user.user_id='$user_id' SQL wouldn't tolerate this ambiguity, since for what it knows, both fields can represent totally different data. The solution is to select each column

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

大憨熊 提交于 2019-11-26 21:34:36
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 only one table is needed and all is well. However, sometimes data is needed from 2 or more of the tables and it needs to be sorted by a user defined column. This is where I am having problems. data columns: id, band_name, song_name, album_name, genre MySQL statment: SELECT * from us_music, de_music where `genre` = 'punk' MySQL spits out this error: