Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Created September 1, 2016 18:17
Show Gist options
  • Save matthewpoer/5712c86c782e30076d09572caf197ea4 to your computer and use it in GitHub Desktop.
Save matthewpoer/5712c86c782e30076d09572caf197ea4 to your computer and use it in GitHub Desktop.
Use this SQL to find all valid + deleted groupings and line items for a given Quote. If you use this in Sequel Pro then you can easily use it's UI to un-delete records
select
quotes.name,products.name,products.quantity,products.cost_price,
products.discount_price,
quotes.id as quotes_id,
quotes.deleted as quotes_deleted,
product_bundle_quote.id as product_bundle_quote_id,
product_bundle_quote.deleted as product_bundle_quote_deleted,
product_bundles.id as product_bundles_id,
product_bundles.deleted as product_bundles_deleted,
product_bundle_product.id as product_bundle_product_id,
product_bundle_product.deleted as product_bundle_product_deleted,
products.id as products_id,
products.deleted as products_deleted
from quotes
join product_bundle_quote on product_bundle_quote.quote_id = quotes.id
join product_bundles on product_bundles.id = product_bundle_quote.bundle_id
join product_bundle_product on product_bundle_product.bundle_id = product_bundles.id
join products on products.id = product_bundle_product.product_id
join products_cstm on products.id = products_cstm.id_c
where quotes.id = '<>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment