I've got 2 tables: interviews & interview_keywords.
An interview has 5 sorted keywords. I need a list of interviews with specified keywords in the right positions of the sorted list. This is what I've got so far, which isn't working:
SELECT i.id,
i.title
FROM interviews AS i
LEFT JOIN interview_keywords AS ik ON i.id = ik.interview_id
WHERE i.cat_id = 1
AND ( (ik.keyword_id = 39 AND ik.sort = 1)
AND (ik.keyword_id = 33 AND ik.sort = 2)
AND (ik.keyword_id = 51 AND ik.sort = 3)
AND (ik.keyword_id = 96 AND ik.sort = 4)
AND (ik.keyword_id = 97 AND ik.sort = 5))
SELECT i.id, i.title
FROM interviews i
INNER JOIN interview_keywords ik1
ON ik1.interview.id = i.id
AND ik.keyword_id = 39
AND ik1.sort = 1
INNER JOIN interview_keywords ik2
ON ik2.interview.id = i.id
AND ik2.keyword_id = 33
AND ik2.sort = 2
INNER JOIN interview_keywords ik3
ON ik3.interview.id = i.id
AND ik3.keyword_id = 51
AND ik3.sort = 3
INNER JOIN interview_keywords ik4
ON ik4.interview.id = i.id
AND ik4.keyword_id = 96
AND ik4.sort = 4
INNER JOIN interview_keywords ik5
ON ik5.interview.id = i.id
AND ik5.keyword_id = 97
AND ik5.sort = 5
WHERE i.cat_id = 1
Related
I have query with many joins and I'm searching for optimization for it.
It's about computers:
For examples I have:
Lenovo 8gbRAM 1TB core i5 ips etc. (all these after brand name are attributes)
I have configuration where, I want to change attribute 8gbRAM to 16gbRAM and I have to search for other item with all these attributes and 16gbRAM
Two tables:
**st_item**
- id
- name
...
**st_item_specification_attribute**
- id
- st_item_id
- attribute_id
- attribute_value_id
...
My problem is that my item has 15 attributes. When I tested with lower number of attributes I use this structure of query and it works, but now system has 85k items and over 1kk item attributes
This is the query:
SELECT `st_item`.id FROM `st_item`
LEFT JOIN `st_item_specification_attribute` `sisa_36590` ON st_item.id = sisa_36590.item_id AND sisa_36590.attribute_id = 365
LEFT JOIN `st_item_specification_attribute` `sisa_367910` ON st_item.id = sisa_367910.item_id AND sisa_367910.attribute_id = 367
LEFT JOIN `st_item_specification_attribute` `sisa_374641` ON st_item.id = sisa_374641.item_id AND sisa_374641.attribute_id = 374
LEFT JOIN `st_item_specification_attribute` `sisa_378366` ON st_item.id = sisa_378366.item_id AND sisa_378366.attribute_id = 378
LEFT JOIN `st_item_specification_attribute` `sisa_382500` ON st_item.id = sisa_382500.item_id AND sisa_382500.attribute_id = 382
LEFT JOIN `st_item_specification_attribute` `sisa_372134` ON st_item.id = sisa_372134.item_id AND sisa_372134.attribute_id = 372
LEFT JOIN `st_item_specification_attribute` `sisa_41268` ON st_item.id = sisa_41268.item_id AND sisa_41268.attribute_id = 412
LEFT JOIN `st_item_specification_attribute` `sisa_413368` ON st_item.id = sisa_413368.item_id AND sisa_413368.attribute_id = 413
LEFT JOIN `st_item_specification_attribute` `sisa_414929` ON st_item.id = sisa_414929.item_id AND sisa_414929.attribute_id = 414
LEFT JOIN `st_item_specification_attribute` `sisa_418496` ON st_item.id = sisa_418496.item_id AND sisa_418496.attribute_id = 418
LEFT JOIN `st_item_specification_attribute` `sisa_385748` ON st_item.id = sisa_385748.item_id AND sisa_385748.attribute_id = 385
LEFT JOIN `st_item_specification_attribute` `sisa_36625` ON st_item.id = sisa_36625.item_id AND sisa_36625.attribute_id = 366
LEFT JOIN `st_item_specification_attribute` `sisa_366355` ON st_item.id = sisa_366355.item_id AND sisa_366355.attribute_id = 366
LEFT JOIN `st_item_specification_attribute` `sisa_366816` ON st_item.id = sisa_366816.item_id AND sisa_366816.attribute_id = 366
LEFT JOIN `st_item_specification_attribute` `sisa_366370` ON st_item.id = sisa_366370.item_id AND sisa_366370.attribute_id = 366
WHERE (`parent_id`=1032) AND
(sisa_36590.attribute_value_id = 2230) AND
(sisa_367910.attribute_value_id = 2451) AND
(sisa_374641.attribute_value_id = 3793) AND
(sisa_378366.attribute_value_id = 2955) AND
(sisa_382500.attribute_value_id = 3879) AND
(sisa_372134.attribute_value_id = 2780) AND
(sisa_41268.attribute_value_id = 3363) AND
(sisa_413368.attribute_value_id = 3373) AND
(sisa_414929.attribute_value_id = 3378) AND
(sisa_418496.attribute_value_id = 3844) AND
(sisa_385748.attribute_value_id = 3036) AND
(sisa_36625.attribute_value_id = 2315) AND
(sisa_366355.attribute_value_id = 2408) AND
(sisa_366816.attribute_value_id = 2412) AND
(sisa_366370.attribute_value_id = 2420)
Query must compare specific pair attribute_id => attribute_value_id, that's the reason my "ON clause" to be with item_id and attribute_id and specific alias
You can use aggregation:
select i.id
from st_item i join
st_item_specification_attribute sisa
ON sisa.item_id = i.item_id
where i.parent_id = 1032 and
(sisa.attribute_id, attribute_value_id) in ( (365, 2230), (367, 2451), . . .)
group by i.id
having count(*) = 15;
You can move your WHERE conditions into ON conditions
and change LEFT JOIN to INNER JOIN.
SELECT `st_item`.id FROM `st_item`
JOIN `st_item_specification_attribute` `sisa_36590`
ON st_item.id = sisa_36590.item_id AND sisa_36590.attribute_id = 365
AND sisa_36590.attribute_value_id = 2230
JOIN `st_item_specification_attribute` `sisa_367910`
ON st_item.id = sisa_367910.item_id AND sisa_367910.attribute_id = 367
AND sisa_367910.attribute_value_id = 2451
...
WHERE `parent_id`=1032
2nd approach
SELECT `st_item`.id FROM `st_item`
JOIN `st_item_specification_attribute` `sisa`
ON st_item.id = sisa.item_id AND
(
(sisa.attribute_id = 365 AND sisa.attribute_value_id = 2230)
OR
(sisa.attribute_id = 367 AND sisa.attribute_value_id = 2451)
...
)
WHERE `parent_id`=1032
GROUP BY `st_item`.id
HAVING COUNT(*) = 15
I cannot predict the performance, but I think you could make on subselect out of all that joins
(I presume atribute_id and Attribute_value_id pairs are unique per item_id)
SELECT `st_item`.id FROM `st_item`
WHERE (`parent_id`=1032) AND
15 = (SELECT COUNT(*) FROM st_item_specification_attribute attr
WHERE `st_item`.id = attr.item_id
AND ( attribute_id = 365 AND attribute_value_id = 2230 OR
...
)
I would use a UNION ALL approach for this. It's easy to change, and fairly simple to read. Performance should be pretty good too:
--A CTE so you only have to change parent_id in one place
--I believe not all mysql versions support this, though
--You could of course just select the parent_id in de UNION ALL and
-- use a single WHERE in the outer query.
WITH st_item_id AS
(
SELECT id
, attribute_id
, attribute_value_id
FROM st_item
WHERE parent_id = 1032
)
SELECT UA.id
FROM (
SELECT st_item.id
FROM st_item_id
INNER JOIN st_item_specification_attribute sisa_36590
ON st_item_id.id = sisa_36590.item_id
AND sisa_36590.attribute_id = 365
AND sisa_36590.attribute_value_id = 2230
UNION ALL
SELECT st_item.id
FROM st_item_id
INNER JOIN st_item_specification_attribute sisa_367910
ON st_item_id.id = sisa_367910.item_id
AND sisa_367910.attribute_id = 367
AND sisa_367910.attribute_value_id = 2451
) UA
I have to write a complex query to get products in MySQL with multiple conditions and stucking on relations with multiple conditions.
The database structure is built from Typo3. At the moment I have 4 joins with multiple conditions. Everything is working fine but the last line of my SQL is the problem. But I can't get any solution.
SELECT p.uid
FROM tx_myext_domain_model_product p
JOIN tx_myext_domain_model_productwirkung w
ON p.uid = w.product
JOIN sys_category_record_mm ck
ON p.uid = ck.uid_foreign
JOIN sys_category_record_mm cc
ON p.uid = cc.uid_foreign
JOIN sys_category_record_mm cw
ON w.uid = cw.uid_foreign
WHERE p.season IN(1,'')
AND p.type = "herbizid"
AND ck.uid_local = 2
AND ck.tablenames = "tx_myext_domain_model_product"
AND ck.fieldname = "culture"
AND cc.tablenames = "tx_myext_domain_model_product"
AND cc.fieldname = "chemicals"
AND cw.tablenames = "tx_myext_domain_model_productwirkung"
AND cw.uid_local IN (2, 395, 257)
AND w.grad = 6;
# and wirkung with cw.uid_local = 2 should have w.grad = 6
# and wirkung with cw.uid_local = 395 should have w.grad = 6
# and wirkung with cw.uid_local = 257 should have w.grad in range from 1 to 6
The 'productwirkung' should have the category 2, 395 and 257 and the 'productwirkung' with the category 2 and 395 should have the grad 6.
I know, with this last line I can't get anything...
EDIT
I cannot add w.grad = 6 because the product should have a productwirkung with the category 257 too with grad 1 - 6. One product has multiple relations with productwirkung. So if there is a product with productwirkung 2 with grad = 6, productwirkung 395 with grad = 6 and productwirkung 257 with grad = 3 I want this product. If I ask for ... cw.uid_local IN (2, 395, 257) AND w.grad = 6 The product wont be selected because productwirkung 257 doesn't has w.grad = 6.
Assuming uid_local is unique, it can not by definition be both 2 and 395
I guess you wanted to go for
...
AND ((`cw`.`uid_local` = 2 AND `w`.`grad` = 6) OR (`cw`.`uid_local` = 395 AND `w`.`grad` = 6));
EDIT
Since in both sub-expressions you're checking for w.grad = 6 this might also be simplified into
...
AND w.grad = 6
AND (cw.uid_local = 2 OR cw.uid_local = 395)
Or even further simplified into
...
AND w.grad = 6
AND cw.uid_local IN (2, 395)
Your problem is that your last two where conditions are conflicting. They state that a row has to contain the cw.uid_local of either 2, 395 or 257 AND must have the ID 2 AND 395 in a single row. If you rewrite the last two lines as an OR conditional, you should get the results you're looking for:
SELECT `p`.`uid`
FROM `tx_myext_domain_model_product` `p`
INNER JOIN `tx_myext_domain_model_productwirkung` `w`
ON `p`.`uid` = w.product
INNER JOIN `sys_category_record_mm` `ck`
ON `ck`.`tablenames` = "tx_myest_domain_model_product"
AND `p`.`uid` = ck.uid_foreign
AND `ck`.`fieldname` = "culture"
INNER JOIN `sys_category_record_mm` `cc`
ON `cc`.`tablenames` = "tx_myext_domain_model_product"
AND `p`.`uid` = cc.uid_foreign
AND `cc`.`fieldname` = "chemicals"
INNER JOIN `sys_category_record_mm` `cw`
ON `cw`.`tablenames` = "tx_myext_domain_model_productwirkung"
AND `w`.`uid` = cw.uid_foreign
WHERE ((`p`.`season` = "1") OR (`p`.`season` = ""))
AND (`p`.`type` = "herbizid")
AND (`ck`.`uid_local` = "2")
AND ((`cw`.`uid_local` IN (2, 395) AND `w`.`grad` = 6) OR `cw`.`uid_local` = 257);
EDIT
Upon reading your edit, I think you'd best be served with subqueries, seeing as your required conditions are conflicting for a single query.
If you want the products where ALL conditions are met (products with "children" that have a (uid_local of 2 AND grad of 6) AND "children" with (uid_local of 395 AND grad of 6) AND "children" with (uid_local of 257 AND grad between 1 and 6)), I would suggest using inner joins with subqueries to constrict your data to the "child cases":
SELECT DISTINCT p.uid
FROM tx_myext_domain_model_product p
### WHERE cw.uid_local = 2 AND w.grad = 6
JOIN (
SELECT p_1.uid
FROM tx_myext_domain_model_product p_1
JOIN tx_myext_domain_model_productwirkung w_1
ON p_1.uid = w_1.product
JOIN sys_category_record_mm cw_1
ON w_1.uid = cw_1.uid_foreign
WHERE cw_1.tablenames = "tx_myext_domain_model_productwirkung"
AND cw_1.uid_local = 2
AND w_1.grad = 6
) p1 ON p1.uid = p.uid
### WHERE cw.uid_local = 395 AND w.grad = 6
JOIN (
SELECT p_2.uid
FROM tx_myext_domain_model_product p_2
JOIN tx_myext_domain_model_productwirkung w_2
ON p_2.uid = w_2.product
JOIN sys_category_record_mm cw_2
ON w_2.uid = cw_2.uid_foreign
WHERE cw_2.tablenames = "tx_myext_domain_model_productwirkung"
AND cw_2.uid_local = 395
AND w_2.grad = 6
) p2 ON p2.uid = p.uid
### WHERE cw.uid_local = 257 AND w.grad BETWEEN 1 AND 6
JOIN (
SELECT p_3.uid
FROM tx_myext_domain_model_product p_3
JOIN tx_myext_domain_model_productwirkung w_3
ON p_3.uid = w_3.product
JOIN sys_category_record_mm cw_3
ON w_3.uid = cw_3.uid_foreign
WHERE cw_3.tablenames = "tx_myext_domain_model_productwirkung"
AND cw_3.uid_local = 257
AND w_3.grad BETWEEN 1 AND 6
) p3 ON p3.uid = p.uid
JOIN tx_myext_domain_model_productwirkung w
ON p.uid = w.product
JOIN sys_category_record_mm ck
ON p.uid = ck.uid_foreign
JOIN sys_category_record_mm cc
ON p.uid = cc.uid_foreign
JOIN sys_category_record_mm cw
ON w.uid = cw.uid_foreign
WHERE p.season IN(1,'')
AND p.type = "herbizid"
AND ck.uid_local = 2
AND ck.tablenames = "tx_myest_domain_model_product"
AND ck.fieldname = "culture"
AND cc.tablenames = "tx_myext_domain_model_product"
AND cc.fieldname = "chemicals";
If we rewrite your query, we get (amongst other things) the following:
AND cw.uid_local = 2
AND cw.uid_local = 395
Unless uid_local occupies some sort of quantum state, this is unlikely to be successful.
FWIW, I find this (slightly) easier to read...
SELECT p.uid
FROM tx_myext_domain_model_product p
JOIN tx_myext_domain_model_productwirkung w
ON p.uid = w.product
JOIN sys_category_record_mm ck
ON p.uid = ck.uid_foreign
JOIN sys_category_record_mm cc
ON p.uid = cc.uid_foreign
JOIN sys_category_record_mm cw
ON w.uid = cw.uid_foreign
WHERE p.season IN(1,'')
AND p.type = "herbizid"
AND ck.uid_local = 2
AND ck.tablenames = "tx_myest_domain_model_product"
AND ck.fieldname = "culture"
AND cw.uid_local IN (2, 395, 257)
AND cw.tablenames = "tx_myext_domain_model_productwirkung"
AND cc.tablenames = "tx_myext_domain_model_product"
AND cc.fieldname = "chemicals"
AND w.grad = 6;
this is my query:
SELECT phpbb_attachments.attach_id, phpbb_attachments.post_msg_id
FROM phpbb_attachments
INNER JOIN phpbb_topics
ON phpbb_attachments.topic_id = phpbb_topics.topic_id
INNER JOIN phpbb_forums ON phpbb_topics.forum_id = phpbb_forums.forum_id
WHERE phpbb_attachments.is_orphan = 0
AND phpbb_attachments.thumbnail = 1
AND (phpbb_attachments.extension = 'jpg'
OR phpbb_attachments.extension = 'png'
OR phpbb_attachments.extension = 'gif')
AND phpbb_forums.forum_id BETWEEN 668 AND 679
ORDER BY phpbb_attachments.attach_id DESC
LIMIT 50
I want to get only the latest 1 attachment per topic.
So sort of like a distinct on phpbb_attachments.topic_id
This query gives the "best" attachment per ropic:
SELECT MAX(a.attach_id), t.topic_id
FROM phpbb_attachments a
INNER JOIN phpbb_topics t ON a.topic_id = t.topic_id
INNER JOIN phpbb_forums f ON t.forum_id = f.forum_id
WHERE a.is_orphan = 0
AND a.thumbnail = 1
AND (a.extension = 'jpg' OR a.extension = 'png' OR a.extension = 'gif')
AND f.forum_id BETWEEN 668 AND 679
GROUP BY t.topic_id
Then select attachments from that list:
SELECT x.attach_id, x.post_msg_id
FROM phpbb_attachments x INNER JOIN (SELECT MAX(a.attach_id) AS attach_id, t.topic_id
FROM phpbb_attachments a
INNER JOIN phpbb_topics t ON a.topic_id = t.topic_id
INNER JOIN phpbb_forums f ON t.forum_id = f.forum_id
WHERE a.is_orphan = 0
AND a.thumbnail = 1
AND (a.extension = 'jpg' OR a.extension = 'png' OR a.extension = 'gif')
AND f.forum_id BETWEEN 668 AND 679
GROUP BY t.topic_id) i ON x.attach_id = i.attach_id
ORDER BY x.attach_id DESC
LIMIT 50
The id of SELECT phpbb_attachments.attach_id, phpbb_attachments.post_msg_id is not the same.
Now when you execute that Script even using SELECT distinct phpbb_attachments.attach_id, phpbb_attachments.post_msg_id, it will not generate a distinctphpbb_attachments.attach_id`.
The Reason is:
It will creating two distinct with this fields phpbb_attachments.attach_id, phpbb_attachments.post_msg_id
Now if you need a Distinct to this phpbb_attachments.attach_id
You have to do it first distinct:
SELECT Distinct phpbb_attachments.attach_id
FROM phpbb_attachments
INNER JOIN phpbb_topics
ON phpbb_attachments.topic_id = phpbb_topics.topic_id
INNER JOIN phpbb_forums ON phpbb_topics.forum_id = phpbb_forums.forum_id
WHERE phpbb_attachments.is_orphan = 0
AND phpbb_attachments.thumbnail = 1
AND (phpbb_attachments.extension = 'jpg'
OR phpbb_attachments.extension = 'png'
OR phpbb_attachments.extension = 'gif')
AND phpbb_forums.forum_id BETWEEN 668 AND 679
ORDER BY phpbb_attachments.attach_id DESC
LIMIT 50
then use left join to that particular Distinct Data using phpbb_attachments.attach_id itself something like:
SELECT attach_id,post_msg_id
FROM
(SELECT Distinct phpbb_attachments.attach_id,
FROM phpbb_attachments
INNER JOIN phpbb_topics
ON phpbb_attachments.topic_id = phpbb_topics.topic_id
INNER JOIN phpbb_forums ON phpbb_topics.forum_id = phpbb_forums.forum_id
WHERE phpbb_attachments.is_orphan = 0
AND phpbb_attachments.thumbnail = 1
AND (phpbb_attachments.extension = 'jpg'
OR phpbb_attachments.extension = 'png'
OR phpbb_attachments.extension = 'gif')
AND phpbb_forums.forum_id BETWEEN 668 AND 679
ORDER BY phpbb_attachments.attach_id DESC
LIMIT 50) as firstDistinct
LEFT JOIN
(SELECT phpbb_attachments.attach_id, phpbb_attachments.post_msg_id
FROM phpbb_attachments
INNER JOIN phpbb_topics
ON phpbb_attachments.topic_id = phpbb_topics.topic_id
INNER JOIN phpbb_forums ON phpbb_topics.forum_id = phpbb_forums.forum_id
WHERE phpbb_attachments.is_orphan = 0
AND phpbb_attachments.thumbnail = 1
AND (phpbb_attachments.extension = 'jpg'
OR phpbb_attachments.extension = 'png'
OR phpbb_attachments.extension = 'gif')
AND phpbb_forums.forum_id BETWEEN 668 AND 679
ORDER BY phpbb_attachments.attach_id DESC
LIMIT 50) as secondNotDistinct
On firstDistinct.attach_id = secondNotDistinct.attach_id
I have the following mysql query
select m.flat_id,
f.flat_no,
fo.owner_name,
oc.occupant_name,
b.block_name,
f.floor_no,
f.floor_id,
m.user_id as user_map_id
from svk_apt_flats_users_mapping m
left join svk_apt_users u on u.user_id = m.user_id and u.association_id = 2
and u.customer_id = 2 and u.is_active = 1 and u.user_id is not null
left join svk_apt_flats f on f.flat_id = m.flat_id and f.is_active = 1
left join svk_apt_blocks b on b.block_id = f.block_id and b.is_active = 1
left join svk_apt_flat_owners fo on u.user_role_type_id = 4 and fo.is_active = 1 and fo.user_id = m.user_id
left join svk_apt_occupants oc on u.user_role_type_id = 5 and oc.is_active = 1 and oc.user_id = m.user_id
where f.block_id = 3
and m.user_id <> 2
and m.customer_id = 2
and m.association_id = 2
and m.is_active = 1
and m.is_active = 1
and (case when m.user_role_type_id = 5 then true else m.is_approved = 1 end)
and Output :
I want to aggregate the rows who have same 'user_map_id' into one row.
Is there any solutions in mysql ?
Use group by
select m.flat_id,
f.flat_no,
fo.owner_name,
oc.occupant_name,
b.block_name,
f.floor_no,
f.floor_id,
m.user_id as user_map_id
from svk_apt_flats_users_mapping m
left join svk_apt_users u on u.user_id = m.user_id and u.association_id = 2
and u.customer_id = 2 and u.is_active = 1 and u.user_id is not null
left join svk_apt_flats f on f.flat_id = m.flat_id and f.is_active = 1
left join svk_apt_blocks b on b.block_id = f.block_id and b.is_active = 1
left join svk_apt_flat_owners fo on u.user_role_type_id = 4 and fo.is_active = 1 and fo.user_id = m.user_id
left join svk_apt_occupants oc on u.user_role_type_id = 5 and oc.is_active = 1 and oc.user_id = m.user_id
where f.block_id = 3
and m.user_id <> 2
and m.customer_id = 2
and m.association_id = 2
and m.is_active = 1
and m.is_active = 1
and (case when m.user_role_type_id = 5 then true else m.is_approved = 1 end)
group by u.user_role_type_id;
MySQL will pick the values of the first row for all columns if you do not specifiy an aggregate function like SUM, AVG etc. onto them
When somebody tries to search for a ticket, as admin, I get an email with this error.
OsTicket v1.11.0-rc1 (e321982)
[SELECT SQL_CALC_FOUND_ROWS A1.`number` AS `number`, A1.`ticket_id` AS `ticket_id`, A1.`source` AS `source`, A1.`created` AS `created`, A8.`subject` AS `cdata__subject`, A1.`isoverdue` AS `isoverdue`, B0.`name` AS `user__name`, A8.`priority` AS `cdata__priority`, B1.`firstname` AS `staff__firstname`, B1.`lastname` AS `staff__lastname`, B2.`name` AS `team__name`, A1.`team_id` AS `team_id`, A1.`isanswered` = '1' AS `8MwwjGf`, (SELECT COUNT(R0.`id`) AS `count` FROM `ost_thread` Q7 JOIN `ost_ticket` Q8 ON (Q7.`object_type` = 'T' AND Q7.`object_id` = Q8.`ticket_id`) LEFT JOIN `ost_thread_entry` R0 ON (Q7.`id` = R0.`thread_id`) WHERE Q8.`ticket_id` = A1.`ticket_id` AND NOT R0.`flags` & 4 != 0) AS _thread_count, (SELECT COUNT(R1.`id`) AS `count` FROM `ost_thread` Q7 JOIN `ost_ticket` Q8 ON (Q7.`object_type` = 'T' AND Q7.`object_id` = Q8.`ticket_id`) LEFT JOIN `ost_thread_entry` R0 ON (Q7.`id` = R0.`thread_id`) LEFT JOIN `ost_attachment` R1 ON (R1.`type` = 'H' AND R0.`id` = R1.`object_id`) WHERE Q8.`ticket_id` = A1.`ticket_id` AND R1.`inline` = 0) AS _att_count, COALESCE(B1.`firstname`, B1.`lastname`, B2.`name`, 'zzz') AS `assignee` FROM `ost_ticket` A1 JOIN `ost_ticket_status` A2 ON (A1.`status_id` = A2.`id`) LEFT JOIN `ost_thread` A3 ON (A3.`object_type` = 'T' AND A1.`ticket_id` = A3.`object_id`) LEFT JOIN `ost_thread_referral` A4 ON (A3.`id` = A4.`thread_id`) LEFT JOIN `ost_staff` A5 ON (A4.`object_type` = 'S' AND A4.`object_id` = A5.`staff_id`) LEFT JOIN `ost_team` A6 ON (A4.`object_type` = 'E' AND A4.`object_id` = A6.`team_id`) LEFT JOIN `ost_department` A7 ON (A4.`object_type` = 'D' AND A4.`object_id` = A7.`id`) LEFT JOIN `ost_ticket__cdata` A8 ON (A1.`ticket_id` = A8.`ticket_id`) JOIN `ost_user` B0 ON (A1.`user_id` = B0.`id`) LEFT JOIN `ost_staff` B1 ON (A1.`staff_id` = B1.`staff_id`) LEFT JOIN `ost_team` B2 ON (A1.`team_id` = B2.`team_id`) JOIN (SELECT COALESCE(Z3.`object_id`, Z5.`ticket_id`, Z8.`ticket_id`) as `ticket_id`, SUM(MATCH (Z1.title, Z1.content) AGAINST ('black8' IN NATURAL LANGUAGE MODE)) AS `relevance` FROM `ost__search` Z1 LEFT JOIN `ost_thread_entry` Z2 ON (Z1.`object_type` = 'H' AND Z1.`object_id` = Z2.`id`) LEFT JOIN `ost_thread` Z3 ON (Z2.`thread_id` = Z3.`id` AND Z3.`object_type` = 'T') LEFT JOIN `ost_ticket` Z5 ON (Z1.`object_type` = 'T' AND Z1.`object_id` = Z5.`ticket_id`) LEFT JOIN `ost_user` Z6 ON (Z6.`id` = Z1.`object_id` and Z1.`object_type` = 'U') LEFT JOIN `ost_organization` Z7 ON (Z7.`id` = Z1.`object_id` AND Z7.`id` = Z6.`org_id` AND Z1.`object_type` = 'O') LEFT JOIN ost_ticket Z8 ON (Z8.`user_id` = Z6.`id`) WHERE MATCH (Z1.title, Z1.content) AGAINST ('black8' IN NATURAL LANGUAGE MODE) GROUP BY `ticket_id`) Z1 WHERE A1.`ticket_id` = Z1.`ticket_id` AND ((A2.`state` = 'open' AND (A1.`staff_id` = 7 OR A5.`staff_id` = 7 OR A1.`team_id` IN (5) OR A6.`team_id` IN (5))) OR A1.`dept_id` IN (1, 4, 5) OR A7.`id` IN (1, 4, 5)) GROUP BY A1.`number`, A1.`ticket_id`, A1.`source`, A1.`created`, A8.`subject`, A1.`isoverdue`, B0.`name`, A8.`priority`, B1.`firstname`, B1.`lastname`, B2.`name`, A1.`team_id` LIMIT 25]
Can't find FULLTEXT index matching the column list
---- Backtrace ----
0 (root)/include/mysqli.php(199): osTicket->logDBError('DB Error #1191', '[SELECT SQL_CAL...')
1 (root)/include/class.orm.php(3404): db_query('SELECT SQL_CALC...', true, true)
2 (root)/include/class.orm.php(3451): MySqlExecutor->execute()
3 (root)/include/class.orm.php(2063): MySqlExecutor->getArray()
4 (root)/include/class.orm.php(2013): HashArrayIterator->{closure}()
5 (root)/include/class.orm.php(1992): CallbackSimpleIterator->next()
6 (root)/include/class.orm.php(2001): CallbackSimpleIterator->rewind()
7 (root)/include/class.orm.php(1673): CallbackSimpleIterator->valid()
8 (root)/include/class.orm.php(1708): CachedResultSet->fillTo(1)
9 (root)/include/class.orm.php(1569): CachedResultSet->offsetGet(0)
10 (root)/include/class.orm.php(1437): QuerySet->offsetGet(0)
11 (root)/include/class.orm.php(1394): QuerySet->exists(true)
12 (root)/include/staff/templates/queue-tickets.tmpl.php(79): QuerySet->total()
13 (root)/scp/tickets.php(543): require_once('/var/www/html/u...')
14 {main}
I ran
ALTER TABLE `ost__search` ADD FULLTEXT(title,content);
And that fixed the problem.