Welcome Guest, Not a member yet? Register   Sign In
Denormalize a table or How to avoid records repeating in DB join
#1

[eluser]earlyriser[/eluser]
Hi.
I have the next tables and columns:
BUSINESS: id, name
CATEGORY: id, cat_name
MIX: id, cat_id, business_id
KEYWORD: id, keyword_name
MIXK: id, keyword_id, business_id


And what I need is to make a query for all the business in some category and get their related keyword, but I don`t know how to make the joins for the last part.

I have this
Code:
$this->db->select('b.name, b.description, b.code, b.address,         m.category_id, m.business_id');
$this->db->from('business b');
$this->db->where('category_id', $category_from_form);
$this->db->join('mix m','b.id = m.business_id');
$this->db->join('mixk mk','b.id = mk.business_id');

What I get i all the business in the category that I want but the business are repeated for every keyword they are related.

For example
If I have just 1 business with 2 keywords (let's say "Best Western" as business and keywords: "cheap" "everywhere" I got 2 result rows and I would like to obtain just one.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB