Querys MYSQL PERTENCE

-2

I need to make a query in mysql , within the WHERE I need that is containing COD_IDENT within a group. That is:

COD_IDENT 
5
6
7

My query must return all results where COD_IDENT is equal to 5,6,7

I tried to do using in however it returns only one result. Actually, it was back to two.

I did it this way:

SELECT COD_IDENT_REUNI, COD_IDENT_SALAX 
  FROM tbl_REUNIOES WHERE COD_IDENT_EMPRE = 'ibhr' and COD_IDENT_SALAX in
    (SELECT COD_IDENT_SALAX, max(DAT_IDENT_REUNI) 
      FROM tbl_REUNIOES WHERE COD_IDENT_EMPRE = 'ibhr' GROUP BY (COD_IDENT_SALAX))
    
asked by anonymous 05.02.2016 / 18:32

1 answer

2

Renan, your IN will not work because you are passing more than one parameter to it, see the documentation IN .

If I understand correctly, you can solve your problem with a SubQuery , like this:

SELECT   A.COD_IDENT_REUNI, B.MAX_COD_IDENT_REUNI
  FROM   TBL_REUNIOES A, (  SELECT   COD_IDENT_SALAX, MAX (DAT_IDENT_REUNI) MAX_COD_IDENT_REUNI
                              FROM   TBL_REUNIOES
                             WHERE   COD_IDENT_EMPRE = 'ibhr'
                          GROUP BY   (COD_IDENT_SALAX)) B
 WHERE   A.COD_IDENT_REUNI = B.MAX_COD_IDENT_REUNI AND A.COD_IDENT_EMPRE = 'ibhr'

There are other means, but this form caters to your problem.

    
05.02.2016 / 19:14