views:

37

answers:

3

I have a table feeds that contains a collection of code-description rows. e.g.

Key | Value      | Url                    
fb  | facebook   | http://www.facebook.com
tw  | twitter    | http://twitter.com     
ff  | friendfeed | http://friendfeed.com  

A REST endpoint returns the contents of this table as a JSON array & it is displayed in a drop down box of a web page.

Today the boss wants the contents to be sorted in a specific manner. And I would like you to comment on my designs.

Design 1

I add a separate column into feeds called rank to denote the order of the item.

Key | Value      | Url                     | Rank
fb  | facebook   | http://www.facebook.com | 3
tw  | twitter    | http://twitter.com      | 1
ff  | friendfeed | http://friendfeed.com   | 2

Design 2

I create a separate table FeedRank that stores the rank.

Key | Rank
fb  | 3
tw  | 1
ff  | 2

Analysis

I am leaning towards design #1 because I can dispense with the JOIN. What are the pros and cons of each design & which one would you use ?

Thanks

+1  A: 

If it's a one-to-one relationship, there's no real reason to put it in a separate table. Go with #1, imo.

Amber
A: 

Design 1 is just fine. Design 2 is essentially the same as design 1 but with unnecessary complexity.

Cryo
+1  A: 

the only reason to put the rankings in a separate table are if either a) the relationship between the code-descriptions and the rankings was not 1:1 or if b) the column was sparsely populated (most of the rows having a NULL value)

even in the latter case most people would de-normalize and place the ranking column in the code-descriptions table.

emh