我有一个复杂的查询,它在 phpmyadmin 中运行良好,但每当我尝试在 php 中使用它时,我都会收到一条错误消息,指出 LIMIT 和 UNION 不允许一起使用。 我添加了 LIMIT 来加快查询速度(因此子选择只会查找 100 行,而不是数千个可能的结果)——这确实有效(它确实加快了查询速度)
现在我从 mysql 切换到 maria_Db,虽然查询仍然适用于 phpmyadmin(插入 112 行),但它只是在 php 上发出错误消息
有什么想法吗?
insert ignore into paulsim2_dokumente_autofill.suche_intern_cache_helper select sysdate(), 'prometheus' as bb,
id, w_tit,w_key, w_uni,w_sim,w_pln,w_len, such_union, 100 from ( select distinct id, w_tit,w_key, w_uni,w_sim,w_pln,w_len, such_union
from ( ( SELECT a.ID as id, 'tit' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.titel_u8) AGAINST('prometheus') > 1
LIMIT 0,100 ) UNION ( SELECT a.ID as id, 'key' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.keywords_titel_u8) AGAINST('prometheus') > 1
LIMIT 0,100 ) UNION ( SELECT a.ID as id, 'uni' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus') > 1
LIMIT 0,100 ) UNION ( SELECT a.ID as id, 'sim' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, 1 as w_pln, 10 as w_len from dokument as a where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE)
LIMIT 0,50 ) UNION ( SELECT a.ID as id, 'pln' as such_union, MATCH(a.titel_u8) AGAINST('>prometheus' IN BOOLEAN MODE)* MATCH(a.titel_u8) AGAINST('prometheus')+1 as w_tit, MATCH(a.keywords_titel_u8) AGAINST('prometheus')+1 as w_key, MATCH(a.keywords_uni_typ_cat_u8) AGAINST('prometheus')+1 as w_uni, MATCH(a.keywords_simple_u8) AGAINST('+prometheu' IN BOOLEAN MODE) *MATCH(a.keywords_simple_u8) AGAINST('prometheu') +1 as w_sim, MATCH(x.plain_u8) AGAINST('"prometheus"' IN BOOLEAN MODE) *MATCH(x.plain_u8) AGAINST('"prometheus"') +1 as w_pln, 10 as w_len from dokument as a, dokumente_text as x where freigegeben in (1,3) and aktiv=1 and a.id <> -1 and x.id = a.id and MATCH(x.plain_u8) AGAINST('"prometheus"')
LIMIT 0,50 ) UNION ( select 1 as id, 'dum' as such_union,-1 as w_tit,-1 as wkey, -1 as w_uni, -1 as w_sim, -1 as w_pln, -1 as w_len from dokument where 1 Limit 0,1 )
order by (w_tit)*(w_key)*w_uni*w_sim*w_pln desc Limit 0, 500 ) as tneu ) as tnx
最佳答案
我发现了我的错误,它在另一个地方。 我有一个 pow(-1,1.2) 并且不再允许,没有设置 mysql> SET sql_mode = '';
关于mysql - phpmyadmin 接受查询而 php 带来错误 UNION 和 LIMIT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59425966/