错误:使用的SELECT语句有不同数量的列,怎么解决呢? [英] Error: The used SELECT statements have a different number of columns, how is fix it?

查看:2716
本文介绍了错误:使用的SELECT语句有不同数量的列,怎么解决呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导致此错误的原因是什么?如何解决?

What is causes this error? How can fix it?

$find = 'hello';
$data = $this->db->query('SELECT * FROM tour_foreign_residence WHERE name LIKE "%' . $find . '%" UNION SELECT * FROM tour_foreign WHERE name LIKE "%' . $find . '%"');

错误:


发生数据库错误
错误号码:1222
所使用的SELECT
语句具有不同的列数
SELECT * FROM
tour_foreign_residence WHERE name LIKE%hello% UNION SELECT * FROM
tour_foreign WHERE名称LIKE%hello%
文件名:
D:\ xampp\htdocs\system\database\DB_driver.php
行号:330

A Database Error Occurred
Error Number: 1222
The used SELECT statements have a different number of columns
SELECT * FROM tour_foreign_residence WHERE name LIKE "%hello%" UNION SELECT * FROM tour_foreign WHERE name LIKE "%hello%"
Filename: D:\xampp\htdocs\system\database\DB_driver.php
Line Number: 330


推荐答案

使用 UNION 运算符:


  1. 计数和排序查询的列在联合查询中应该相等

  2. 必须与相应列中的数据类型兼容

在您的情况下,系统会忽略第一条规则。
use join 而不是

In your case, first rule is ignored. use join operator instead

这篇关于错误:使用的SELECT语句有不同数量的列,怎么解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆