简体   繁体   中英

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. 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. 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!:(

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

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

2 select id,concat(trim(movieName), '_', year) as title from Featuredfilms_EN and put in $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

}`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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