dimanche 6 septembre 2015

Why does nested query in SQLite return the wrong value?

I'm dealing with the yelp dataset on sqlite3, and I have a schema as follows:

    CREATE TABLE businesses
     (business_id text primary key,
      name text,
      full_address text,
      city text,
      stars decimal(1,1),
      ratings integer);

I run the following query:

     select name, stars from businesses where ratings >= 400;

And I get the following:

    Pho Kim Long |3.5
    Pho So 1     |3.5
    Ichiza       |4
    ...
    Guy Fieri    |3.5
    Giada        |4

If I run:

    select name, min(stars) from businesses where ratings >= 400;

I get The Quad Las Vegas Resort & Casino|2

But if I run:

    select name 
    from (select name, min(stars) 
          from businesses 
          where ratings >= 400);

I get Giada.

I know that there's a way to do this with LIMIT X, but why does this occur in the first place? Is there something about the SQLite parser that I'm neglecting?

Aucun commentaire:

Enregistrer un commentaire