Filter not working with count and join

QuestionsFilter not working with count and join
Tim Moore asked 2 years ago

Anyone know how to keep filters working using this or similar query?

$g->select_command = “SELECT * FROM tbl_customer
LEFT JOIN (SELECT fk_customer, count(*) as total
FROM tbl_job GROUP BY fk_customer) as t ON fk_customer = customer_id
LEFT JOIN (SELECT fk_customer_id, count(*) as tcontact
FROM tbl_contacts GROUP BY fk_customer_id) as tc ON fk_customer_id = customer_id
“;

it tries to use the joins in the filter: below is the error

Couldn’t execute query. Unknown column ‘company_name’ in ‘where clause’ – SELECT count(*) as c FROM (SELECT * FROM tbl_customer LEFT JOIN (SELECT fk_customer, count(*) as total FROM tbl_job WHERE 1=1 AND ( `company_name` LIKE ‘%d%’ ) GROUP BY fk_customer) as t ON fk_customer = customer_id LEFT JOIN (SELECT fk_customer_id, count(*) as tcontact FROM tbl_contacts GROUP BY fk_customer_id) as tc ON fk_customer_id = customer_id ) pg_tmp

 

Thanks,

Tim

2 Answers
Abu Ghufran Staff answered 2 years ago

I’ll be updating here again after regenerating this query testcase.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Abu Ghufran Staff answered 2 years ago

Hello,

Apologies for the extreme delay.

I tested this query case and it works with the latest build. I saw that You recently updated the subscription and the updated build should solve it.

v2.8 output:

SELECT count(*) as c FROM (SELECT * FROM tbl_customer LEFT JOIN (SELECT fk_customer, count(*) as total FROM tbl_job GROUP BY fk_customer) as t ON fk_customer = customer_id LEFT JOIN (SELECT fk_customer_id, count(*) as tcontact FROM tbl_contacts GROUP BY fk_customer_id) as tc ON fk_customer_id = customer_id WHERE 1=1 AND ( `company_name` LIKE ‘%jo%’ )) pg_tmp

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

7 + 15 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?