?
Solved

Develop a query exploding values in a column and comparing

Posted on 2013-02-03
5
Medium Priority
?
221 Views
Last Modified: 2013-02-05
I have a table contest_setup and it contains (simplified)

id
account_id
ContestName
ContestStartDate

the ContestStartDate column contains dates that a particular contest will run ie:
2013-02-18 00:00:00,2013-02-19 04:00:00,2013-02-20 16:00:00
(this contest would run on 3 different dates for example)

Some rows may contain just one date, others a few like above.

My question is: how can I construct a query to check for all the Contests that may be running on 2013-02-19 (from 00:00:00 to 23:59:59) and arrange them by date/time soonest to latest?

I'm guessing I need to go through the rows that belong to a certain account_id that would be passed to it (for example '17'),

I need to explode the ContestStartDate on the comma and check the values for the date I'm interested in and somehow 'magically' display them earliest to latest.

Can anyone throw me a bone to get going in the right direction? Its beyond my ability currently.
0
Comment
Question by:tjyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 38849630
Make a Google search for "Should I normalize my database" and read the interesting opinions on either side of the idea.  In the instant case, the answer for you is "Yes, I must normalize."  Any column that contains more than one atomic data element is a recipe for catastrophe.  So create a "junction table" to connect your contest_setup table to your contest_dates table.  Put all the dates in a row of the contest_dates table, using the column data type of DATETIME.
0
 
LVL 1

Author Comment

by:tjyoung
ID: 38854192
Hi,
changed my approach but not sure about the junction table or why to use one?
Here is where I'm at now:

2 tables
contest_setup - id (auto), contestname, account_id
contest_dates - contestsetup_id, contestdate(datetime)

So I'm thinking I would be able to query contests slated for today for example by joining the tables and matching up the id and the contestsetup_id where its todays date and the account_id is 'x'

That right? I wasn't sure how or why you would introduce a junction table.

I haven't got to querying the tables etc. yet so if there is a fatal flaw, I may have just not come across it at this point.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38854519
I don't see anything wrong with that design.  You may find that you do not need a junction table and you can just use the JOIN clause.  Be sure to index any columns used in JOIN, just as you would index any columns used in WHERE, and add LIMIT statements if possible.

Best regards, ~Ray
0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 38854668
very good advice.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38854734
Thanks for the points, it's a great question, ~Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question