I have a table with the following data named registers :
--------------------------------------------------------------
id_plague | id_production | quadrant
--------------------------------------------------------------
4 | 3 | 1
--------------------------------------------------------------
4 | 3 | 2
--------------------------------------------------------------
4 | 3 | 3
--------------------------------------------------------------
3 | 3 | 1
--------------------------------------------------------------
4 | 4 | 1
--------------------------------------------------------------
4 | 4 | 2
--------------------------------------------------------------
3 | 4 | 1
--------------------------------------------------------------
4 | 5 | 1
--------------------------------------------------------------
The table records the pests that were found in a X crop, the crop is divided into beds and each bed is divided into squares. In this case the bed is the id_production and the boxes are the field quadrant .
The table records that the pest was found in each bed frame.
What I need is to count the number of frames that have been registered in the crop, so much so that I can make a simple query like this:
SELECT COUNT(quadrant) AS total
FROM registers;
and it gives me the following result
--------------
total
--------------
8
--------------
The problem is that in a table you can register several pests, then save one record per pest per box.
--------------------------------------------------------------
id_plague | id_production | quadrant
--------------------------------------------------------------
4 | 3 | 1
--------------------------------------------------------------
4 | 3 | 2
--------------------------------------------------------------
4 | 3 | 3
--------------------------------------------------------------
3 | 3 | 1
--------------------------------------------------------------
In this table specifically with these records you can see that:
- That in the table with value 1 there are two pests with value 4 and 3
- In squares with value 2 and 3 they have a plague with value 4
By doing COUNT these records specifically I will give 4 and what I want is that no matter how many pests have a single table I only count it once, that is, in this case to do COUNT I want me to 3 because he found pests in tables 1, 2 and 3
I'm only interested to know how many paintings are infected. I hope you can make me understand with this question hehehehe