I have a small jpg of what I believe is a fan trap. I would like to get some other opinions before I start changing things around and adding another relationship when I may not to.
What I am trying to do is loop data between the "event" and "customer_Phone" tables. My loop does not give me the correct information and now that I am looking at the design, I am seeing that I possibly have a fan trap going on here. Can someone please confirm this for me?
Basically, the loop says, give me all of the customer_Phone numbers where the event_Id = something.
Your ERD looks fine to me. What exactly are you worried about happening? Also, I hope you weren't serious about using a loop...
Hi Blindman, thanks for the response. Using this:
SELECT * FROM `customer` Inner Join `event` ON `customer`.`customer_Id` = `event`.`customer_Id` Inner Join `customer_Phone` ON `customer`.`customer_Id` = `customer_Phone`.`customer_Id` WHERE `event`.`customer_Location_Id` = '1' AND `event`.`event_Number_Id` = '3'
Customer_Location_Id is a FK and even though it is not shown in the jpg, it is there.
What I need is ALL phone numbers returned from the customer_Phone table where the customer_Id = something AND the event_Number = something. I am not getting the correct results though. I have 3 records in the db as sample data but I am only getting 2 returned.
I was actually was serious about looping the data but through the web application, not sql. No good?
Rudy, thanks for the reply. I will absolutely take your advice and stop using the backticks. The sql I posted today was from a stack I was having a problem with and was written prior to you enlightening me yesterday. I will go through my code and take them out. I don’t like them either. In the code you formatted, I can see the immediate changes. Much cleaner indeed.
As far as me not getting the correct result set back, that was due to a programming error on my part. I just couldn't seem to pinpoint where the problem was until now.
Maybe I am going about this whole entire process in the wrong way, and please let me know if I am, but the joins I am writing are quite long and several stacks have several sql statements. Instead of joining 10 tables together, I have decided to do smaller chunks of sql code and break it up.
From a complete “readability” standpoint in the programming code of the UI, I have put all of the sql code on one line. I do not like this either and I am wondering if there is another way to do this. When I have an issue like I did today, I have to extract the sql and then format it so it becomes readable again so that I can troubleshoot it.