2
Good morning.
I have the following tables in a Mysql database:
BOIS
------------
| id | boi |
------------
| 12 | 77 |
| 22 | 8 |
| 14 | 12 |
------------
BOIS_MANEJO
---------------------
| id | fk_boi| peso |
---------------------
| 1 | 14 | 217 |
---------------------
| 2 | 22 | 217 |
---------------------
| 3 | 14 | 250 |
---------------------
The following Query brings me all ids of oxen.
SELECT *
FROM bois
WHERE
id NOT IN(
SELECT CONCAT("'", GROUP_CONCAT(DISTINCT(m.fk_boi) SEPARATOR "','"), "'") FROM bois_manejo AS m
)
I get ID 12 only with the following formulas.
SELECT id
FROM bois
WHERE
id NOT IN(14, 22)
# OU id NOT IN('14', '22')
How I can use GROUP_CONCAT with numbers, or how I can resolve this situation?
Thanks in advance.
What is the expected result?
– Filipe L. Constante
@Constant, the expected result is ID 12. It is the only one not in the table bois_manejo.
– E. Coelho
I don’t understand why you try another way, since you already have the select that brings you the expected result..
– Filipe L. Constante
@Constant, I don’t have the SELECT that brings the 12. If you’re talking about the SELECT that worked (the second one) it works just because I know the codes that are there. The goal of the query is to bring me the results as there is change in the table’s base/feed. The first select brings me all the Ids.
– E. Coelho
@E.Rabbit which entrance and exit you expect?
– Sorack
So, from what I understand, you need to make a select that brings a result based on a change from another table, in this case (bois_manejo), is that it? Can you be a little clearer in your doubt? :)
– Filipe L. Constante
@Sorack, as you can see, I’m trying to get the WHERE clause to take all the Foreng Keys that exist in the table bois_manejo (with a DISTINCT) and give me all the Ids that are not in bois_manejo. In the example the only ID that is not in table bois_manejo is 12.
– E. Coelho
@Filipel.Constant fk_boi is a Foreng Key related to the ID of the table ox. I need to bring only the Ids of oxen that have not been weighed/handled yet. :)
– E. Coelho
All right, I understood the structure of the table I didn’t understand how I know they were or weren’t weighed/handled yet! hehe :)
– Filipe L. Constante
@E.Rabbit do you have the need to use group_concat?? is there a problem using other alternatives??
– Oliveira
Good morning, @Oliveira. I’m open to alternatives. So far I’m stuck in this. :)
– E. Coelho