0

I'll describe my scenario so you guys understand what type of design pattern I'm looking for.

I'm making an application where I provide someone with a link that is associated with one or more files. For example, someone needs somePowerpoint.ppx, main.cpp and somevid.mp4, and I have a tool that makes kj13h1djdsja213j1hhadad9933932 associated with those 3 files so that I can give someone

mysite.com/getfiles?fid=kj13h1djdsja213j1hhadad9933932

and they'll get a list of those files that they can download individually or all at once.

Since I'm new to SQL, the only way I know of doing that is having my tool use a table like

     fid                        |          filename
------------------------------------------------------------------
kj13h1djdsja213j1hhadad9933932            somePowerpoint.ppx
kj13h1djdsja213j1hhadad9933932            main.cpp
kj13h1djdsja213j1hhadad9933932            somevid.mp4
jj133823u22h248884h4h24h01h232            someotherfile.someextension

to go along with the above example. It would be nice if I could do some equivalent of

     fid                        |          filename(s)
---------------------------------------------------------------------------
kj13h1djdsja213j1hhadad9933932      somePowerpoint.ppx, main.cpp, somevid.mp4
jj133823u22h248884h4h24h01h232            someotherfile.someextension

but I'm not sure if that's possible or if I should be using some other design pattern altogether.

Any advice?

user4905335
  • 371
  • 2
  • 13
  • 3
    You need store the information as the first format. You can get the result in your second format later. – Tim3880 Jun 01 '15 at 17:16
  • Isn't the first format inefficient? There has to be a better way. – user4905335 Jun 01 '15 at 17:35
  • 1
    @user4905335 The first format may be a bit less efficient (definitely in terms of disk space, difficult to say in terms of query performance without a benchmark), but it also makes the database much easier to maintain. With a relational database you'll generally want to start out with a [normalized](http://en.wikipedia.org/wiki/Database_normalization) format (like your first format) - only switch to a denormalized format (like your second format) if your benchmarks call for it. – Zim-Zam O'Pootertoot Jun 01 '15 at 17:43

1 Answers1

0

I believe Concatenate many rows into a single text string? can help give you a query that would generate your condensed format (you'd still want to store it in SQL with the full list, but you could make a view showing the condensed version using the query in the link)

Community
  • 1
  • 1
Stephen S.
  • 1,616
  • 16
  • 14