How can I ignore two results in a specific query?

0

I have a query that gives me the start and end of each user, but what I want is to omit two users in specific, how can I manage to omit two results?

I have the following query:

SELECT 
    nombre, MIN(fecha) desde, MAX(fecha) hasta
FROM
    tnames
WHERE
    fecha > '2014%'
        AND nombre IN (SELECT DISTINCT
            nombre 
        FROM
            tnames 
        WHERE fecha > '2014%') GROUP BY nombre

Result:

-----------------------------------
nombre    |   desde    |    hasta
-----------------------------------
luis      | 2016-07-01 | 2016-08-01
marco     | 2017-01-01 | 2017-04-25
juan      | 2016-01-05 | 2016-02-20
pedro     | 2016-04-15 | 2016-01-02
mario     | 2016-03-05 | 2017-03-03

How could I get the following that does not appear in my result the names of Marco and Pedro :

-----------------------------------
nombre    |   desde    |    hasta
-----------------------------------
luis      | 2016-07-01 | 2016-08-01
juan      | 2016-01-05 | 2016-02-20
mario     | 2016-03-05 | 2017-03-03
    
asked by Houdini 02.05.2017 в 18:58
source

1 answer

3

Having your query we would only have to add another condition to our WHERE in the following way:

SELECT 
    nombre, MIN(fecha) desde, MAX(fecha) hasta
FROM
    tnames
WHERE
    fecha > '2014%'
        AND nombre IN 
           (
            SELECT DISTINCT
                nombre 
            FROM
                tnames 
            WHERE fecha > '2014%' AND
                nombre NOT IN ('marco', 'pedro') # Añade esto a tu consulta
           ) 
GROUP BY nombre

You can also do as commented by colleague Lixus in his comment, using operator != (different from) or operator <> ( no equal to)

SELECT 
    nombre, MIN(fecha) desde, MAX(fecha) hasta
FROM
    tnames
WHERE
    fecha > '2014%'
        AND nombre IN 
           (
            SELECT DISTINCT
                nombre 
            FROM
                tnames 
            WHERE fecha > '2014%' AND
                nombre != 'marco' AND nombre != 'pedro' # Añade esto a tu consulta
                # nombre <> 'marco' AND nombre <> 'pedro'
           ) 
GROUP BY nombre
    
answered by 02.05.2017 / 19:14
source