mysql-error-1052

PHP & MYSQL: How to resolve ambiguous column names in JOIN operation?

倖福魔咒の 提交于 2019-11-26 10:25:49
I have two tables in my database: NEWS ('id' - the news id, 'user' - the user id of the author) USERS ('id' - the user id) I want to make a SELECT * FROM news JOIN users ON news.user = user.id , now when I get the results in PHP it's something like: $row = mysql_fetch_array($result) , and get column names by $row['column-name'] ... how do I get the news ID and the user ID, having the same column name? UPDATE: Thanks everybody for the quick answers. Aliases seem the best solution. You can set aliases for the columns that you are selecting: $query = 'SELECT news.id AS newsId, user.id AS userId,

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

て烟熏妆下的殇ゞ 提交于 2019-11-26 09:06:51
问题 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,

MySQL 'user_id' in where clause is ambiguous problem

拟墨画扇 提交于 2019-11-26 08:37:13
问题 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\' 回答1: 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,

PHP & MYSQL: How to resolve ambiguous column names in JOIN operation?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 03:28:09
问题 I have two tables in my database: NEWS (\'id\' - the news id, \'user\' - the user id of the author) USERS (\'id\' - the user id) I want to make a SELECT * FROM news JOIN users ON news.user = user.id , now when I get the results in PHP it\'s something like: $row = mysql_fetch_array($result) , and get column names by $row[\'column-name\'] ... how do I get the news ID and the user ID, having the same column name? UPDATE: Thanks everybody for the quick answers. Aliases seem the best solution. 回答1