Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 26th, 2012  |  syntax: SQL  |  size: 1.19 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (SELECT
  2.         `bo`.`id`,
  3.         `bo`.`to`,
  4.         `bo`.`message`,
  5.         `bf`.`from`,
  6.         `bo`.`priority`,
  7.         NULL AS `gw_spam_id`,
  8.         NULL AS `bb_id`
  9. FROM
  10.     `bulk_outbox` `bo`, `bulk_from` `bf`
  11. WHERE
  12.     `bo`.`bulk_batch_id` IS NULL
  13.     AND `bo`.`status` = 'queued'
  14.     AND (`bo`.`begin` < NOW() OR `bo`.`begin` IS NULL)
  15.     AND `bo`.`created` + INTERVAL 1 MONTH > NOW()
  16.     AND `bo`.`created` <= NOW()
  17.     AND `bf`.`id` = `bo`.`bulk_from_id`
  18. ORDER BY
  19.     bo.priority DESC
  20. LIMIT 100
  21. )
  22. UNION
  23. (
  24. SELECT
  25.     `bo`.`id`,
  26.     `bo`.`to`,
  27.     `bo`.`message`,
  28.     `bf`.`from`,
  29.     `bo`.`priority`,
  30.     `bb`.`gw_spam_id`,
  31.     `bb`.`id` AS `bb_id`
  32. FROM
  33.     `bulk_batch` `bb`, `bulk_from` `bf`, `bulk_outbox` `bo`
  34. WHERE
  35.     `bo`.`bulk_batch_id` IS NOT NULL
  36.     AND `bb`.`status` IN ('queued', 'sending')
  37.     AND `bo`.`status` = 'queued'
  38.     AND (`bb`.`begin` < NOW() OR `bb`.`begin` IS NULL)
  39.     AND `bo`.`created` + INTERVAL 1 MONTH > NOW()
  40.     AND `bo`.`created` <= NOW()
  41.     AND `bf`.`id` = `bb`.`bulk_from_id`
  42.     AND `bo`.`bulk_batch_id` = `bb`.`id`
  43. ORDER BY
  44.     `bb`.`status` DESC,
  45.     `bb`.`priority` DESC
  46. LIMIT 100
  47. )
  48. ORDER BY
  49.     priority DESC
  50. LIMIT 100