I have a table (“presentations”) with these columns:
PresentationTitle | Speaker1 | Speaker2 | Speaker3
This works great for listing all of the presentation titles like this on my “Presentations” page:
Presentation Number One
by:
John Smith
Pocahontas Smith
John Rolfe
Presentation Number Two
by:
Grandmother Willow
Presentation Number Three
by:
Chief Powhatan
Kocoum Derpyderpderp
But now, for my “Speakers” page, I need to list all of the speakers–independent of each other–in alphabetical order. Like this:
Chief Powhatan
Grandmother Willow
John Rolfe
John Smith
Kocoum Derpyderpderp
Pocahontas Smith
What’s the best way to do this?
Another note–In my real-life table, the speaker1 column has lots more columns attached to it– “middlename”, “lastname”, “headshot”, “age”… and speaker2 has “middlename2”, “lastname2”, “headshot2,” etc… I need to keep these pieces of info attached to those speakers.
Thanks in advance for helping a big noob like me 🙂
You should rethink your database design. A better table layout would be something more like:
Then you can do a query like this to list all speakers from a particular presentation in alphabetical order by first name:
Or a query as simple as this for all speakers in alphabetical order by first name:
This is better for many reasons. Having a bunch of extra columns for every speaker will be difficult to deal with (which is the trouble you’re having now), plus you’ll have a ton of columns which may not be used (depending on the number of speakers), which may waste space, and another big reason…what if you get a presentation in which there are more speakers than you have columns?
My way is much more flexible and much easier to perform simple operations (like sorting). You can have any number of speakers for each presentation, and there is no wasted space taken up with unused columns.