![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi, I have this query / subquery that is acting strange. *I am trying to get the latest status of a customers Trial subscription and Paid subscription. *The customer may have 1, both or neither. But, in the case where the customer has 1, say a Trial and not a Paid, the entire query fails and returns nothing. *Any thoughts? |
#3
| |||
| |||
|
|
On Apr 12, 9:52*pm, The Magnet <a... (AT) unsu (DOT) com> wrote: Hi, I have this query / subquery that is acting strange. *I am trying to get the latest status of a customers Trial subscription and Paid subscription. *The customer may have 1, both or neither. But, in the case where the customer has 1, say a Trial and not a Paid, the entire query fails and returns nothing. *Any thoughts? A cartesian product of result sets where at least one result set is empty is still empty. You need a different approach if any of these queries can return 0 rows. The most simple transformation (without thinking about the efficiency of your current approach) would be to turn the two in-line views into scalar subqueries of a main query on DUAL like select (query for trail_status) as trail_status, (query for paid_status) as paid_status from dual; Since you queries are guaranteed to return at most a single row this should work. Regards, Randolf Oracle related stuff blog:http://oracle-randolf.blogspot.com/ Co-author of the "OakTable Expert Oracle Practices" book:http://www.apress.com/book/view/1430...Administration... |
#4
| |||
| |||
|
|
Hi, I have this query / subquery that is acting strange. *I am trying to get the latest status of a customers Trial subscription and Paid subscription. *The customer may have 1, both or neither. But, in the case where the customer has 1, say a Trial and not a Paid, the entire query fails and returns nothing. *Any thoughts? SELECT trial_status, paid_status FROM (SELECT trial_status * * * * * *FROM (SELECT co.status trial_status, ROW_NUMBER() OVER (ORDER BY order_date DESC) rnum * * * * * * * * * * * FROM customer_order_vw co, newsletter_subscription ns * * * * * * * * * * * WHERE customer_id = 732126295 * * * * * * * * * * * * *AND subproduct_id = 197 * * * * * * * * * * * * *AND co.code = ns.code * * * * * * * * * * * * *AND subscr_type = 'Trial') * * * * * * WHERE rnum = 1), * * * * * *(SELECT paid_status * * * * * * FROM (SELECT co.status paid_status, ROW_NUMBER() OVER (ORDER BY order_date DESC) rnum * * * * * * * * * * * * FROM customer_order_vw co, newsletter_subscription ns * * * * * * * * * * * * WHERE customer_id = 732126295 * * * * * * * * * * * * * * *AND subproduct_id = 197 * * * * * * * * * * * * * * *AND co.code = ns.code * * * * * * * * * * * * * * *AND subscr_type <> 'Trial') * * * * * * WHERE rnum = 1); |
#5
| |||
| |||
|
|
Hi, I have this query / subquery that is acting strange. *I am trying to get the latest status of a customers Trial subscription and Paid subscription. *The customer may have 1, both or neither. But, in the case where the customer has 1, say a Trial and not a Paid, the entire query fails and returns nothing. *Any thoughts? SELECT trial_status, paid_status FROM (SELECT trial_status * * * * * *FROM (SELECT co.status trial_status, ROW_NUMBER() OVER (ORDER BY order_date DESC) rnum * * * * * * * * * * * FROM customer_order_vw co, newsletter_subscription ns * * * * * * * * * * * WHERE customer_id = 732126295 * * * * * * * * * * * * *AND subproduct_id = 197 * * * * * * * * * * * * *AND co.code = ns.code * * * * * * * * * * * * *AND subscr_type = 'Trial') * * * * * * WHERE rnum = 1), * * * * * *(SELECT paid_status * * * * * * FROM (SELECT co.status paid_status, ROW_NUMBER() OVER (ORDER BY order_date DESC) rnum * * * * * * * * * * * * FROM customer_order_vw co, newsletter_subscription ns * * * * * * * * * * * * WHERE customer_id = 732126295 * * * * * * * * * * * * * * *AND subproduct_id = 197 * * * * * * * * * * * * * * *AND co.code = ns.code * * * * * * * * * * * * * * *AND subscr_type <> 'Trial') * * * * * * WHERE rnum = 1); |
![]() |
| Thread Tools | |
| Display Modes | |
| |