Jump to content

Help with this select query


arenaninja

Recommended Posts

I'm trying to get a fee schedule table to work. The fee schedule table itself:

CREATE TABLE `feeschedule` (
  `pkFeeSchdID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `fkEquipID` int(10) unsigned NOT NULL,
  `fkInstTypeID` int(10) unsigned NOT NULL,
  `rate` decimal(5,2) DEFAULT NULL,
  PRIMARY KEY (`pkFeeSchdID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

It stores the equipment, the institution type, and a rate for that institution type.

 

The table is currently empty. However, I'm trying to query this table to also retrieve the associated data from fkEquipID and fkInstTypeID, with just the 'rate' values coming as 'NULL' (the reason why is because a new instTypeID or EquipID could be inserted into the db at any time, and in that case I still need to have one row per instTypeID). I've attached an image which is sample of what I need to come out. The code below is what I've tried. I've alternated between Right joins and left joins but I'm really just shooting in the dark here. Any suggestions would be welcome.

SELECT feeschedule.*, equip.equipid,equip.name,equip.name_short, insttypes.* FROM feeschedule RIGHT JOIN equip on (feeschedule.fkEquipID=equip.equipid) RIGHT JOIN insttypes on (feeschedule.fkInstTypeID=insttypes.instTypeID)

post-128265-13482403314864_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/258950-help-with-this-select-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.