Welcome Guest, Not a member yet? Register   Sign In
sub query problem
#1

[eluser]Bigil Michael[/eluser]
i have written a subquery like this, but value of total is null. can anyone help me to solve this issue


Code:
SELECT LD.dst_district as district, kk.total_property FROM loc_district as LD
LEFT JOIN ( SELECT RQ.req_id,COUNT(RQ.req_id) as total_property FROM
req_requirement AS RQ WHERE RQ.verified = 1 ) AS kk
ON LD.dst_id = kk.req_id WHERE `LD`.`st_id` = 3 GROUP BY LD.dst_id ORDER BY LD.dst_district
#2

[eluser]Bigil Michael[/eluser]
bump..
#3

[eluser]Bigil Michael[/eluser]
any help ???
#4

[eluser]Tim Brownlaw[/eluser]
It's a little difficult to work out when all we have is the statement and no other information...

So does it work ( ie no errors ) when you throw it into phpmyadmin or the like...
Have you tried breaking it down and testing the "bits" before trying the whole catastrophe...

Taking it in small steps is a great way to learn how this all works, especially if the result is not what you are expecting.

So time for you to debug it and only you can do that - as you have all the tables and data - we don't!

You can do it!

Cheers
#5

[eluser]Bigil Michael[/eluser]
I have fixed the bug by modifying query like this

Code:
SELECT LD.dst_id as district_id,LD.dst_district as district, kk.total_property FROM loc_district as LD
       LEFT JOIN ( SELECT RQ.req_district as distict_id,COUNT(RQ.req_id) as total_property FROM
       req_requirement AS RQ WHERE RQ.verified = 1 GROUP BY distict_id ) AS kk
       ON LD.dst_id = kk.distict_id WHERE `LD`.`st_id` = 3 GROUP BY LD.dst_id ORDER BY LD.dst_district
#6

[eluser]Tim Brownlaw[/eluser]
Glad to hear it!
Well done!


Can you mark this as solved!


Cheers
Tim




Theme © iAndrew 2016 - Forum software by © MyBB