Hello, I'm having trouble doing the following query:
I have 3 tables: users_categories , main_bucks and new_bucks
When a user creates a budget, the system creates a record in primary_budget with the main information, which is: Who created the budget, end date, status, etc.
In the new_counts table, the specification for each item is: item name (eg inks), quantity, details and category of the item (paint => painting) Record ID in primary orcamentos
The question is: in the table users_categories the categories of the supplier are saved, and this can be several types, such as paints, glasses,
So what I need is that when a buyer submits the budget (which can contain multiple categories) all suppliers ( category_users ) that have at least ONE budget category, is returned in QUERY
Then I have the following:
usuarios_categorias
ID_user | ID_categoria
1 1 (tintas)
1 2 (vidros)
1 3 (elevador)
orcamentos_novo
Titulo | ID_categoria
Vidros 2
Calhas 5
Piscina 8
Notice that in users_categories the user has the category Glasses, but does not have the others, however it is to return all the records (Glasses, gutters, pools) because it has at least one category
I can not figure out a QUERY for this, what I currently have:
SELECT COUNT(*) as QTD_orc FROM orcamentos_principal
JOIN orcamentos_novo
ON orcamentos_novo.id_orcamento = orcamentos_principal.id
WHERE orcamentos_principal.status = 'ativo'
It fetches all records but does not check if the user has at least one category
NOTE: I am the supplier, when I enter the page of budgets available he will have to seek all budgets that I have at least ONE category, you see? so I need to return all the records for primary_budgets where I have at least one of the new_budgets categories associated with it