简体   繁体   English

连接两个没有唯一公共字段的mysql表

[英]joining two mysql tables without unique common field

I made a big mistake in inserting data from my survey application and now I really stuck! 我在从调查应用程序插入数据时犯了一个大错误,现在我真的很坚持! I have list of movies in my table "featuredfilms_EN" with these fields: movieName, ImdbId(unique Id of movies), year. 我的“ featuredfilms_EN”表中有以下电影的列表, 其中包含以下字段: movieName,ImdbId(电影的唯一ID),年份。 In my survey app, I asked users about their favorite movies and I stored their answers in the "Answer_CROWD" table which has these fields: qId, answer. 在调查应用程序中,我向用户询问了他们最喜欢的电影,并将他们的答案存储在“ Answer_CROWD”表中,该表具有以下字段: qId,答案。 Now I faced a big problem that is: I need to join these two tables, but since I forgot to store the unique_Id(ImdbId) in "Answer_CROWD" table, I cannot!:( 现在,我面临一个大问题:我需要联接这两个表,但是由于我忘记将unique_Id(ImdbId)存储在“ Answer_CROWD”表中,所以我不能!:(

I appreciate if someone can help me if there is a way that I can join these two tables? 如果有人可以加入这两个表格,我是否能帮助我,我深表感谢。 I am really stuck... I have a deadline tomorrow and I just found this big issue now. 我真的被困住了……我明天有个截止日期,现在我才发现这个大问题。

it looks like you could concat the movieName & year & match on that 看来您可以在此连接上movieName和year及match

SELECT * FROM featuredfilms_EN 
JOIN Answer_CROWD ON lower(answer)=lower(concat(trim(movieName), '_', year))

I write here because in comment will be confused, now i can't see fields of tables so i write generic but i'think you understand: 我在这里写是因为在评论中会很困惑,现在我看不到表的字段,所以我写了泛型但我想你理解:

update query: 更新查询:

1 add a field called for example Film_id to Answer_CROWD 1将一个名为例如Film_id的字段添加到Answer_CROWD

2 select id,concat(trim(movieName), '_', year) as title from Featuredfilms_EN and put in $rows 2从Featuredfilms_EN中选择id,concat(trim(movieName),'_',year)作为标题并放入$ rows

3 in a 三合一

`foreach ($rows as $value ){
$id=$value['id'];
$title=$value['title'];
$sql="UPDATE Answer_CROWD SET Film_id='$id' WHERE  lower(answer)=lower('$title')";

....do query

}`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM