Zend certified PHP/Magento developer

SQL for getting promos applied to an order

I require an SQL query to retrieve information about the promotions applied to an order from the sales order table. The field “applied_rule_ids” is utilized to obtain all rule IDs. However, a challenge arises when a rule, such as “buy 2 get 1 free,” is stored in both the sales_order and quote tables. The issue lies in the application of this rule, where its ID is present in the quote even if the shopping cart contains only one item. Consequently, when placing an order with a single item, the rule ID is included in “applied_rule_ids,” causing the SQL query to display the order as having a promotion applied, even though it is not actually applied.