Skip to main content
Inspiring
December 9, 2008
Question

determine which table to get records from

  • December 9, 2008
  • 1 reply
  • 469 views
Hi,
I hope I am going about this the right way, if not, I am open to better ways. I have two tables, one is to take requests from the user and another for the edits of those same records, by the admin. Essentially a request table(bcastreq.cfm) and an edit table(editbcastreq.cfm). On the main screen(admin), I have a list of all the requests and a count of all current edits for each individual record. What I need to do is dynamically determine which record to get, and from the correct table. When an admin goes in to select a record they will see that the requests either has edits or does not, indicated by a count. When an admin selects a record to edit, if there has been no edits at all, indicated with a 0 to the selected record it will need to pull the data from the bcastreq table, if there are edits indicated by the count, indicated by a X number it will need to pull the very last edited record for that selection. ex. If the selection currently has 10 edits, I need it to pull that 10th edited record from the edit table to start another edit, which will in turn when finished will create the 11th edit and show accordingly on the main admin screen. If it has zero edits it will need to pull the data from the request table, which will eventually create the first edit. What is the best way to handle this?
This topic has been closed for replies.

1 reply

Inspiring
December 9, 2008
The answer depends on the db you are using. You are looking for a function named ifnull, coalesce, or something like that.

And you are going to have to do a left join to a subquery.
rmorganAuthor
Inspiring
December 9, 2008
It is mysql 5. I will look up the functions you suggested.