Note that there are some explanatory texts on larger screens.

plurals
  1. POAlternatives to "WHERE IN (...)"?
    primarykey
    data
    text
    <p>I've got a project under way which has gotten a little out of hand (in terms of being well organized and thought out) as it started very small and has grown quite quickly.</p> <p>Anyhow, we have a system which tracks user activity, records UUIDS and also specific contact activity which we use to generate information as to exactly what the customer has been viewing on the site. Pretty standard. Anyhow, its gotten a bit complex and slow and I am hoping for some help optimizing the query.</p> <p>I'm sure there is a much better way to do it (using JOINS perhaps) than I am currently using, but I can't seem to get my head around it. Some help would be appreciated. Associated info is below.</p> <p>Thanks.</p> <p><strong>Table: visitor_activity</strong></p> <pre>CREATE TABLE `visitor_activity` ( `vaid` int(11) NOT NULL AUTO_INCREMENT, `uuid` varchar(128) DEFAULT NULL, `ip_address` varchar(15) DEFAULT NULL, `datetime` datetime DEFAULT NULL, `url` varchar(255) DEFAULT NULL, `user_agent` varchar(255) DEFAULT NULL, PRIMARY KEY (`vaid`), KEY `uuid` (`uuid`), KEY `ip_address` (`ip_address`) ) ENGINE=MyISAM AUTO_INCREMENT=70134 DEFAULT CHARSET=utf8</pre> <p><strong>Table: contact_uuids</strong></p> <pre>CREATE TABLE `contact_uuids` ( `contact_id` int(11) NOT NULL DEFAULT '0', `uuid` varchar(128) NOT NULL DEFAULT '', PRIMARY KEY (`contact_id`,`uuid`), KEY `contact_id` (`contact_id`), KEY `uuid` (`uuid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8</pre> <p><strong>Table: contact_log</strong></p> <pre>CREATE TABLE `contact_log` ( `contact_log_id` int(11) NOT NULL AUTO_INCREMENT, `contact_id` int(11) NOT NULL, `datetime` datetime NOT NULL, `action` varchar(128) NOT NULL, `performed_by` varchar(64) NOT NULL, `ip_address` varchar(15) NOT NULL, PRIMARY KEY (`contact_log_id`), KEY `contact_id` (`contact_id`), KEY `ip_address` (`ip_address`), KEY `performed_by` (`performed_by`) ) ENGINE=MyISAM AUTO_INCREMENT=9017 DEFAULT CHARSET=utf8</pre> <p><strong>Current SQL Statement:</strong></p> <pre>SELECT DISTINCT(`va`.`vaid`), `va`.`datetime`, `va`.`uuid`, `va`.`ip_address`, `va`.`url` FROM `visitor_activity` `va` WHERE `va`.`uuid` IN (SELECT `uuid` FROM `contact_uuids` `cu` WHERE `cu`.`contact_id` = '1') || `va`.`ip_address` IN (SELECT DISTINCT(`ip_address`) FROM `contact_log` `cl` WHERE `cl`.`contact_id` = '1' && `performed_by` = 'Contact') ORDER BY `va`.`datetime` DES</pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload