Why Between doesn’t bring the right answer

Asked

Viewed 39 times

1

I have a specific table with the data that I do the search (sales_flat_order) where column status has among other values ('entregue', 'entregue_pd', 'entregue_pd_pago', 'avaliacao_solicitado', 'avaliado_negativamente', 'avaliado_positivamente'), but when I use the between does not bring the correct information since when being consulted separately I have return of all this is the script

(
SELECT entity_id, status FROM sales_flat_order where 
(status between 'entregue_pd_pago' 
and 'entregue' 
and 'entregue_pd_pago'
and 'avaliacao_solicitado'
and 'avaliado_negativamente'
and 'avaliado_positivamente'
);
)

I am using Mysql Workbench.

  • 3

    BETWEEN is for checking if a value is in a range. For example, year BETWEEN 2015 AND 2019. It didn’t make any sense in what you tried to do, let alone make it clear what your intention was. You want to return the record if the status be one of those listed?

  • You’re making the wrong use of between you’re trying to make a IN (value1,value2,value3,value4)

  • 1

    would like to return the id s that were with those status but as you yourself mentioned the in must resolve. Anderson Carlos Woss

1 answer

4

Are you making a wrong use of between.

between serves to check if a value is between 2 values. Example

select * from numeros where valor between 0 and 10

The return of the select above would be

0,1,2,3,4,5,6,7,8,9,10

to make a check if a value is within a specific list of values you need to use the IN()

SELECT entity_id, status FROM sales_flat_order 
where status IN (
    'entregue_pd_pago', 
    'entregue',
    'entregue_pd_pago',
    'avaliacao_solicitado',
    'avaliado_negativamente',
    'avaliado_positivamente'
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.