Im making a table generator as a school project.
In MySQL I have 3 tables namely process,operation,score. Everything looked fine until i tested out my “ADD column” button in the web app.
Previous saved data should be read properly but also include the new column in the format, problem is the previous data queried does not include any values for the new table, so I intended it to return a score of 0 if no records were found, tried IFNULL & COALESCE but nothing happens(maybe im just using it wrong)
- process – processID, processName
- operation – operationID, operationName
-
score – scoreID, score, processID, operationID, scoreType (score
types are SELF,GL,FINAL)ps = (PreparedStatement)dbconn.prepareStatement(“SELECT score FROM score WHERE processID=? and operationID=? and type=?ORDER BY processid”);
here’s a pic of a small sample http://i50.tinypic.com/2yv3rf9.jpg
The reason that
IFNULLdoesn’t work is that it only has an effect on values. A result set with no rows has no values, so it does nothing.First, it’s probably better to do this on the client than on the server. But if you have to do it on the server, there’s a couple of approaches I can think of.
Try this:
The
SUMensures that exactly one row will be returned.If you need to return multiple rows when the table contains multiple matching rows then you can use this (omitting the ORDER BY for simplicity):