Search code examples
mysqlsqldb-browser-sqlite

Why DB Browser have an order I can't replicate?


I have an issue I really don't understand. In fact, I have a database of movies where there's a table for actors,containing two colums (movie id and name).

For example, then I enter the movie id of Django Unchained, the first result is Jamie Fox (the main actor). But then I enter, this sql query (i would expect to get Jamie Fox, Christoph and Leonardo):

SELECT * FROM LesActeurs WHERE film_id=68718 ORDER BY acteur LIMIT 3

But I get 3 actors by alphabetical order. Do You Know how could I mimic the DB Browser order with command (I'm a beginner)?

Thank you!

result DB Browser

result SQL


Solution

  • Without any other column to order by, you can't get that result, at least not reliably. Without an explicit order by clause, the database is free to return the rows in whatever order it chooses (often it's just the order in which they were inserted).

    If you want to get reliably get Jamie, Christophe and Leonardo you could add another column (e.g., "importance"), populate it and then query and explicitly order by it.