-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

5
  • Does this answer your question? What is the default order of records for a SELECT statement in MySQL? Commented Dec 30, 2020 at 9: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 Commented Dec 30, 2020 at 9: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 Commented Dec 30, 2020 at 9:24
  • @P.Salmon ok, but why DB BRowser order it by 'popularity' Commented Dec 30, 2020 at 9:24
  • I think you just answered your own question. Commented Dec 30, 2020 at 9:27

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

ok ok, thank you, I'm surprised that db browser have a different order.. I'm gonna change my homework then..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.