views:

33

answers:

1

Hey,
How is it possible to sort data from multiple tables by relevance?

My table structure is following:
I have 3 tables in my database, one table contains the name of solar systems, the second for e.g. of planets. There is one more table, witch is a connection between solar systems and planets.

If I want to get data of a planet, witch is in the Milky Way, i post this data to the server, and it gives me a multi-dimensional array witch contains:

  1. The Milky Way, with every planet in it
  2. Every planet, witch name contains the string Milky Way

(maybe thats a bat example because i don't think that theres but one planet with this name, but the main concept is on file)

But, i want to set the most relevant planets to the top of the array. (for the relevance i would check the description of the planets or something like that)

So, how would you do that kind of data sorting?

+1  A: 

order by in sql will order the results of your query by whatever field you want. You could then use limit to only get the first N results.

Joshua Smith