Igor Ralic
Igor Ralic

Reputation: 15006

Better performance than double SQLite inner join

I have three tables (everything is oversimplified for the question)

Student
---
StudentId (primary key)
UniversityId (indexed)
CityId (indexed)
StudentName


University
---
UniversityId (primary key)
UniversityName


City
---
CityId (primary key)
CityName

I want to print out all the student names, but if names are the same, I want to order first by the CityName where they are from, and then by the UniversityName.

So, I have a simple query like this one:

select s.* from student s 
inner join university u on s.UniversityId = u.UniversityId 
inner join city c on s.CityId = c.CityId 
order by s.StudentName asc, c.CityName asc, u.UniversityName asc

Is there a way to improve performance of this in any way, and how?

Upvotes: 0

Views: 297

Answers (1)

CL.
CL.

Reputation: 180020

The indexes on UniversityId and CityId are not needed.

The ORDER BY could be optimized with an index on StudentName.

Upvotes: 1

Related Questions