Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:27:05+00:00 2026-05-23T20:27:05+00:00

Afternoon all. I’ve recently been tasked with working on an event-based support ticket system,

  • 0

Afternoon all.

I’ve recently been tasked with working on an event-based support ticket system, but I’ve encountered a lot of issues and I think the problem is the database structure.

At the moment it looks a bit like this:

create table tickets (
    ticket_id int not null primary key auto_increment,
    stage_id int not null default 0,
    name varchar(255) not null default ''
    /* etc... */
);
create table ticket_events (
    event_id int not null primary key auto_increment,
    ticket_id int not null,
    date datetime,
    stage_id
);
create table stages (
    stage_id int not null primary key auto_increment,
    name varchar(255)
);

So whenever a ticket changes stage a new row is added to the ticket_events table specifying which stage it moved to and when, and the stage_id field in the tickets table is updated with the new stage.

The problem is that this breaks database normalisation rules, as a ticket has its current stage defined by both tickets.stage_id and the most recent record in the ticket_events table. In my attempt to write a report showing the number of outstanding tickets at any point in time I’ve discovered why it is this way. It seems that it’s very difficult to get any kind of SQL to quickly retrieve the current stage from the events table.

I managed to construct a reasonably fast query using option 2 at this very helpful page (http://kristiannielsen.livejournal.com/6745.html), but I’ve come across an issue that leaves me stuck.

With the current data the event_id does not always run in ascending order relative to date. In addition, due to certain automated processing scripts it is quite possible that one ticket has two events with exactly equal dates. The means that any query trying to use the events table needs to “order by date, event_id”, which is almost impossible to do with subqueries and grouping.

Can anyone give any advice for how I might go about overcoming these issues? Is there a better way of defining the order of events?

Many thanks.
Simon

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:27:05+00:00Added an answer on May 23, 2026 at 8:27 pm

    I would replace the tickets.stage_id with FK to the ticket_events table (last_event) and whenever new event is inserted trigger would update the tickets.last_event field to the PK of the event. This allows easy/quick join to find the current stage from the events table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon, with all the buzz around the iPhone / AppStore etc, I felt
afternoon all. Iv'e come across some mathematical problems that im not too good at.
Afternoon all. Another hour, another question! I have the following bit of jquery up
Afternoon all. I have a gridview that offers a line per line 'feedback' column.
Afternoon all This is driving me nuts. For no apparent reason (of course there
Afternoon all - I'm after a bit of advice really. Being a newbie, I
Afternoon all. Here's an easy one for you that I can't figure out. I
Afternoon all, Using the code below I'm trying to load what is render by
Afternoon all, I tried to add a second data entity to the persistent store
Afternoon all. I have the following scenario: I have a search page where by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.