Skip to content

Tag: mysql

Replace conditional subquery in Order By (Performance consideration)

I have a ratings table (t2) I’m using to sort queries by lower_bound DESC. The problem is, the default value of lower_bound has to be null or 0. When a rating occurs, the row is updated with Wilson’s rating algo. This means that new entries get ordered before all other entries in a lower_bound DES…

SQL if not null update

I have this query UPDATE users SET username = Param1,email = Param2,PASSWORD = Param3 WHERE id = Param4; this is updating my user row, but i want to say: If email OR password is not null update them …

MySQL TIMEDIFF Less than an hour, invalid time

I have a function in MySQL that will select the time someone clocked in, and select the time someone clocked out and link them together. It will calculate how many hours that person has been on the clock in total between two provided dates. I then created another function that selects the break events and sub…

MySQL syntax for summing several count data

I have a MySQL table called things_they_own with two columns: person and thing and my primary key is the combination of the two. Thus, there are several rows where the first column is a certain person with the thing column being different for each, and several rows where the second column is a certain thing a…