MySQL5.7多表查询含相同字段时orderBy使用Convert函数的坑!

MySQL5.7多表查询含相同字段时orderBy使用Convert函数的坑!

mysql版本:5.7

问题产生

执行的多表查询sql语句如下:

select table1.* from table1 join table2 where ... order by convert(column1 using 'gbk') 

如果table1和table2中有相同字段(column1)一样,就会报错。

报错信息:Error 1052: Column 'column1' in order clause is ambiguous

如果这个sql语句中不使用convert函数,是能够指定表为table1的,不报错(因为select table1.*已经指定表)

select table1.* from table1 join table2 where ... order by column1

解决方法

convert函数中的value必须指定表

select table1.* from table1 join table2 where ... order by convert(table1.column1 using 'gbk') 

相关推荐

  1. MySQL - 查询

    2023-12-08 13:04:04       42 阅读
  2. MySQL-查询

    2023-12-08 13:04:04       41 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-08 13:04:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-08 13:04:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-08 13:04:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-08 13:04:04       20 阅读

热门阅读

  1. 数据结构练习——素数统计

    2023-12-08 13:04:04       36 阅读
  2. 【短文】用ssh连接服务器时,怎么指定账户名

    2023-12-08 13:04:04       35 阅读
  3. python学习:opencv学习和numpy学习(持续更新)

    2023-12-08 13:04:04       33 阅读
  4. 蓝桥杯从零开始备战(Python组)---基础知识篇

    2023-12-08 13:04:04       26 阅读
  5. composer配置国内镜像

    2023-12-08 13:04:04       43 阅读
  6. MAC PHP版本安装问题

    2023-12-08 13:04:04       36 阅读
  7. 华为云安全组规则

    2023-12-08 13:04:04       38 阅读
  8. PHP 反序列化字符串逃逸

    2023-12-08 13:04:04       30 阅读
  9. git merge和git rebase

    2023-12-08 13:04:04       23 阅读
  10. react经验6:使用SVG图片

    2023-12-08 13:04:04       35 阅读