-1

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

Elias
  • 77
  • 7
  • Does this answer your question? [What is the default order of records for a SELECT statement in MySQL?](https://dba.stackexchange.com/q/6051/5203) – GSerg Dec 30 '20 at 09:23
  • 1
    'But I get 3 actors by alphabetical order' - that's correct, also data is not stored in any particular order and the fact that db browser shows in a particular order does not alter that – P.Salmon Dec 30 '20 at 09:23
  • 3
    I'd have to ask what you think `ORDER BY acteur` does in that query if getting the actors in alphabetical order *didn't* match your expectation. In general, if you don't specify an `ORDER BY`, the order of results is *non-deterministic* (note, that doesn't mean random) and there doesn't appear to be a column by which you *can* deterministicly order the results as you seem to want – Damien_The_Unbeliever Dec 30 '20 at 09:24
  • @P.Salmon ok, but why DB BRowser order it by 'popularity' – Elias Dec 30 '20 at 09:24
  • I think you just answered your own question. – P.Salmon Dec 30 '20 at 09:27

1 Answers1

0

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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • ok ok, thank you, I'm surprised that db browser have a different order.. I'm gonna change my homework then.. – Elias Dec 30 '20 at 20:09