I have written the following query and it is working fine for a single hostname
SELECT hostname,
orderId,
CASE WHEN status = 30 THEN 'Finished' ELSE 'Error' END 'status',
CASE WHEN status = 30 THEN '' ELSE Heading END 'Heading',
CASE WHEN status = 30 THEN '' ELSE Detail END 'Detail'
FROM(SELECT host.hostname,
cb.orderId,
cb.status,
cb.chefbook_name AS Heading,
(SELECT log_message
FROM chefbookrun rr
WHERE rr.chefbook_id = c.id
ORDER BY id DESC
LIMIT 1 ) AS Detail
FROM host
INNER JOIN host_infl hif ON host.vc_server_id = hif.vc_server_id
INNER JOIN chefcookbook cb ON hif.id = cb.host_id
WHERE host.hostname REGEXP 'abc'
ORDER BY cb.orderId LIMIT 1
) AS temp;
I am getting the output as following:
hostname orderId status Heading Detail
abc.com 3 Finished
I want to run the same query for multiple hostnames. I am performing the change in REGEXP
as below but it is still returning the same output as above and has only a single hostname
WHERE host.hostname REGEXP '^(abc|cde|efg)'
My desired output is as below:
hostname orderId status Heading Detail
abc.com 3 Finished
cde.com 3 Error HeadingA Details1
efg.com 3 Error HeadingA Details1
Sample Data:
hostname orderId status Heading Detail
abc.com 3 30 HeadingA Details1
abc.com 5 40 HeadingB Details2
... more rows
hostname orderId status Heading Detail
cde.com 3 40 HeadingA Details1
cde.com 5 30 HeadingB Details2
... more rows
hostname orderId status Heading Detail
efg.com 3 50 HeadingA Details1
efg.com 5 30 HeadingB Details2
... more rows