My goal is simple: JOIN by IP addresses from different logs; at the client-side I’m trying to determine where JavaScript errors are being spawned from (e.g. humans or bots) which I am inferring from if a isset($row[date_xy]) via PHP.
This query does work fine without ORDER BY, once I throw that in to the mix MySQL jumps to 30% CPU utilization and stays there for a few seconds before I kill the process. I’m testing this locally of course. I want to use ORDER BY je.date DESC as I’m not interested in the oldest possible entries.
I have tried sub-selects, it’s been a while since I’ve done anything fancier than a basic JOIN. It’s important that I keep the syntax SOL-neutral.
SELECT
je.date AS date_js,
lb.date AS date_lb,
lh.date AS date_lh
FROM log_javascript_errors AS je
LEFT JOIN log_bots AS lb ON je.ip = lb.ip
LEFT JOIN log_humans AS lh ON je.ip = lh.ip
ORDER BY je.date DESC
LIMIT 20, 20
I’ve gone a different route as I must admit this the design of the tables did not consider this possibility when I created them originally; we’ve all encountered this. I did learn SQL vendor-neutral CASE syntax however though found out I did not even need to use that after some modifications so I’m up-voting the two replies I received as thanks for expanding my understanding of SQL. For those who find this question directly relevant to their goals I ended up adding a “type” column which I am using the server scripting language to fill in the rest in order to generate what I need to see in my logs. I think if I redesigned it from scratch I would have created a master sessions table for all “types” (humans, search engines and rejects) and then possibly try a double LEFT JOIN though I’m not sure how well that would work offhand.