错误:使用的SELECT语句有不同数量的列,怎么解决呢? [英] Error: The used SELECT statements have a different number of columns, how is fix it?
问题描述
导致此错误的原因是什么?如何解决?
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
运算符:
- 计数和排序查询的列在联合查询中应该相等
- 必须与相应列中的数据类型兼容
在您的情况下,系统会忽略第一条规则。
use join
而不是
In your case, first rule is ignored.
use join
operator instead
这篇关于错误:使用的SELECT语句有不同数量的列,怎么解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!