Click to See Complete Forum and Search --> : Regarding Sql Table...


laptop545
January 27th, 2009, 02:47 PM
Hi Guys...CAn any1 help me on how to search a table...

I have the fields... "ID (unique and primary key)" , " Movie name" , "Genre", "Rating".....

Genre can be Comedy,Drama or Musical
Rating CAN be R, G,PG

Now i have an option in my app to search for movies with genre...that is i have 3 buttons.... Comedy, Drama ,Musical ..If i click any of the button i should get the related MOvies names.....

Same for Rating also...

My problem is if i have all of them in one table...if i have to search(say comedy movies...as they are not in order) i have to search for the entire table to get the answers......Can any1 tell me how to search witout searching the entire table.......

cjard
January 27th, 2009, 06:38 PM
So you want to find all occurrences of X in a table without searching the table for X?

Can you ask your question in a way that makes sense?

Alsvha
January 28th, 2009, 01:48 AM
Well, depending on what database you use, I'd say you should make an index on your Genre would properly be the best approach.
It can speed up a query tremendously if made correct. In your example it looks like an index made on genre and id in that order, would be a good starting point.

That way - if your index is made properly - then you'll not have to scan the entire table, but only go through the index and that is something the database should do for you...... depending on which database you use.