join two data from the same field in MYSQL

1

I want to make a query in MYSQL that allows me to join two data in a field, the field is defined as an INT and I am doing the query by means of a where in but the problem is that it shows them to me but I have used several functions separately as CONCAT or GROUP_CONCAT but none turns out to be correct, here are some screenshots

My main goal is to show me only in the column that says farms, just a row where this 1.2 I only want that, I would be grateful if you will help me

here I leave the code of the SQL query

SELECT GROUP_CONCAT(granja_id) AS total FROM formulario_precebo WHERE granja_id IN (1,2) GROUP BY granja_id
    
asked by Juan Esteban Yarce 23.03.2018 в 17:28
source

1 answer

3

I did a test in SQL fiddle , and it worked for me ok, but yes, I did not use the GROUP BY of the end, since when placing it, I returned the separated results. I suggest you try without that GROUP BY .

SELECT GROUP_CONCAT(granja_id) AS total FROM formulario_precebo WHERE granja_id IN (1,2);

EDIT:

This was the exercise I did in SQL Fiddle:

CREATE TABLE prueba (campo1 TINYINT(3), campo2 VARCHAR(10));
INSERT INTO prueba VALUES (1, 'Mesa'), (1, 'Silla'), (2, 'Estante'), (3, 'Cama');

SELECT GROUP_CONCAT(DISTINCT campo1) AS total FROM prueba WHERE campo1 IN (1, 2);

And this returned me:

  

total

     

1,2

There may be other fields in your table that prevent the query from working as you want: /

    
answered by 23.03.2018 / 17:45
source