I want to get the categories pricing, Say if there is data in **customer\_category\_pricing** table then fetch that pricing for that specific customer. Otherwise fetch default prices from categories table.

i have tried achieving this desired result using mysql case it is working fine, but the problem is, it is returning two rows 

* hourly\_amount\_final column returns updated price then per\_day\_amount\_final returns default price
* Then in next row, hourly\_amount\_final column return default price and then per\_day\_amount\_final returns updated price.

table: pr\_categories

```
---------------------------------------------------------------------------------
| id | title            | hourly_amount | per_day_amount | created_at| updated_at
---------------------------------------------------------------------------------
| 1  | Power Generation | 100.00        | 200.00         | 
| 2  | Local Government | 300.00        | 400.00         |
----------------------------------------------------------

```

table: pr\_customer\_categories\_pricing

```
------------------------------------------------------------------------------------
| id | customer_id | category_id | billing_type_id | amount | created_at | updated_at
------------------------------------------------------------------------------------
| 1  |      1      |      1      |         1       |   109  |
| 2  |      1      |      1      |         2       |   600  |
----------------------------------------------------------

```

table: pr\_billing\_types

```
----------------
| id | title   |
--------------
| 1  | Hourly  |
| 2  | Per Day |
----------------

```

This is the query i am working with at the moment:

```
SELECT c.id,c.title,
CASE
    WHEN (c.hourly_amount <> (SELECT ccp.amount WHERE ccp.billing_type_id = 1)) 
    THEN (SELECT ccp.amount WHERE ccp.billing_type_id = 1)
    ELSE c.hourly_amount
END
AS hourly_amount_final,

CASE
    WHEN (c.per_day_amount <> (SELECT ccp.amount WHERE ccp.billing_type_id = 2)) 
    THEN  (SELECT ccp.amount WHERE ccp.billing_type_id = 2)
    ELSE c.per_day_amount
END
AS per_day_amount_final

FROM pr_customer_category_pricing AS ccp
RIGHT JOIN pr_categories AS c
ON c.id = ccp.category_id AND ccp.customer_id = 1

```

Expected result **when there is no data** in **pr\_customer\_category\_pricing**

```
----------------------------------------------------------------------
| id | title            | hourly_amount_final | per_day_amount_final |
----------------------------------------------------------------------
| 1  | Power Generation |      100.00         |      200.00          | 
| 2  | Local Government |      300.00         |      600.00          |
----------------------------------------------------------------------

```

Expected result **when there is data** in **pr\_customer\_category\_pricing**

```
----------------------------------------------------------------------
| id | title            | hourly_amount_final | per_day_amount_final |
----------------------------------------------------------------------
| 1  | Power Generation |      109.00         |      600.00          | 
| 2  | Local Government |      300.00         |      400.00          |
----------------------------------------------------------------------

```

Actual result what i'm getting:

```
----------------------------------------------------------------------
| id | title            | hourly_amount_final | per_day_amount_final |
----------------------------------------------------------------------
| 1  | Power Generation |      109.00         |      200.00          | 
| 1  | Power Generation |      100.00         |      600.00          |
| 2  | Local Government |      300.00         |      400.00          |
----------------------------------------------------------------------

```

What am i doing wrong? Any suggestions! Help a brother out. :S