Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在多个表的所有列中搜索的最简单方法?_Mysql_Sql - Fatal编程技术网

Mysql 在多个表的所有列中搜索的最简单方法?

Mysql 在多个表的所有列中搜索的最简单方法?,mysql,sql,Mysql,Sql,我有很多桌子: d_customers d_customers d_news d_pages d_products d_projects d_sms 我想创建一个搜索表单,在所有表的所有列中搜索键入的任何单词。。。但是当我写SQL代码时,我发现它很长而且很混乱。。。有谁能告诉我正确的方法吗 'SELECT * FROM d_customers,d_customers,d_news,d_pages,d_products,d_projects,d_sms WHERE ' . $nc_make .

我有很多桌子:

d_customers
d_customers
d_news
d_pages
d_products
d_projects
d_sms 
我想创建一个搜索表单,在所有表的所有列中搜索键入的任何单词。。。但是当我写SQL代码时,我发现它很长而且很混乱。。。有谁能告诉我正确的方法吗

'SELECT * FROM d_customers,d_customers,d_news,d_pages,d_products,d_projects,d_sms
WHERE ' . $nc_make . 'LIKE .....
AND LIKE.... AND LIKE.....  AND LIKE.....  AND LIKE.....  '

我想通过LIKE word搜索所有表格中的所有coulmn…如果我搜索google word,我想选择所有表格中的所有coulmn,其中所有列都像google

,如果表格彼此相关,那么将它们连接起来,并应用您的条件

select *
from customers c
inner join pages p
on p.customer_id=c.customer_id
where customer_name like 'xyz'
如果sql中的联接和条件是必需的,则不能避免它们,但可以对它们进行优化

如果您希望使用编程动态生成查询,然后执行查询,那么在mysql信息_schema中存储与该表中包含的表和字段相关的所有信息。您可以使用它来生成动态sql

希望这有帮助

create table t1(a int);
create table t2(a int, b int);
insert into t1 values (1);
insert into t2 values (1,3);

SELECT *
  FROM (
         (select 't1' as tbl, a as Col1, null as Col2 from t1) 
         union
         (select 't2' as tbl, a as Col1,    b as Col2 from t2)
       ) as U
where U.Col1 = 1 or U.Col2 = 1
结果:

TBL COL1 COL2
t1  1    (null)
t2  1    3

nooo..我想用like搜索所有coulmns中的单词…此代码不使用like搜索…选择*FROM information_schema。
COLUMNS
C WHERE TABLE_schema='YOUR_DATABASE'如果我有一个像google这样的单词,并且想搜索所有像google这样的单词所在的表,该怎么做?我想通过像word…如果我搜索GoogleWord,我想选择所有表格中的所有列,其中所有列(如googlei)都会出错#1222-使用的SELECT语句具有不同的列数。。。。。我认为这是关于列类型的,因为union与类似的列类型一起使用。你有其他解决方案吗,因为我无法更改列类型正如你所看到的,t1表只有一列,而t2表有两列。构建查询时,每个表的列数必须相同,因此使用的是
null作为ColX
。生成查询取决于最大列数。