how to remove single quote ' character in mysql text field?

我只是一个虾纸丫 提交于 2019-12-24 12:36:28

问题


This is my query:

SELECT count(email_details.id) as total_emails,
       email_titles.* 
  FROM email_details 
  LEFT JOIN email_titles ON email_details.email_title = email_titles.title 
 GROUP BY email_details.email_title 
 ORDER BY email_titles.id ASC

Now my problem is email_details.email_title is blob field and email_titles.title is text field, both field has a data with chracter say "this month’s video" when i runs this query without left join the row having chracter does not retrieve, if i put left join then it retrieves only first table data. how to solve this problem?


回答1:


I have solved my problem by my self, i have modified join code like this

LEFT JOIN `email_titles` ON CONVERT( email_details.email_title
USING utf8 ) = CONVERT( email_titles.title
USING utf8 ) 



回答2:


The best option would be to join on something other than those large chunks of text or if that is not possible, make sure that the same text is stored in the same way on both tables.

If that isn't possible either, you need to convert the blob into text for the join, possibly also convert the varchar into char. Something like this

SELECT count(email_details.id) as total_emails,
       email_titles.* 
  FROM email_details 
  LEFT JOIN email_titles 
    ON email_details.email_title = CAST(email_titles.title AS char(100) CHARACTER SET utf8) 
 GROUP BY email_details.email_title 
 ORDER BY email_titles.id ASC


来源:https://stackoverflow.com/questions/28043126/how-to-remove-single-quote-character-in-mysql-text-field

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!