Skip to content

Instantly share code, notes, and snippets.

@Swader
Last active February 2, 2016 21:55
Show Gist options
  • Save Swader/40f2543e13a905600101 to your computer and use it in GitHub Desktop.
Save Swader/40f2543e13a905600101 to your computer and use it in GitHub Desktop.
How would you rewrite this query to be MySQL 5.7 friendly? Currently fails due to new GROUP BY rules.
select *
from ebay_order_items
where
z_shipmentno is null
and ExternalTransactionID is not null
and orderstatus = 'Completed'
and timestamp > '2015-02-25'
group by ExternalTransactionID
order by timestamp desc
@Swader
Copy link
Author

Swader commented Feb 2, 2016

Hat tip to @feketegy for the solution

select extf.* from (
    select ExternalTransactionID
    from ebay_order_items
    where ExternalTransactionID is not null
    group by ExternalTransactionID
) extf JOIN ebay_order_items eoi ON (eoi.ExternalTransactionID = extf.ExternalTransactionID)
where eoi.z_shipmentno is null
and eoi.orderstatus = 'Completed'
and eoi.timestamp > '2015-02-25'
order by eoi.timestamp desc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment