Skip to content
Advertisement

Tag: mysql

Indexing distinct values for a column

I have a table containing a column authors that contains names of authors for different articles (different rows). I want to add a new column that contains a unique index for every author,i.e. let’s say 12 for every occurrence of Dickens (just a random pick) in the author column. Can it be done by a MySQL query or will I

Select row with most recent date per user

I have a table (“lms_attendance”) of users’ check-in and out times that looks like this: I’m trying to create a view of this table that would output only the most recent record per user id, while giving me the “in” or “out” value, so something like: I’m pretty close so far, but I realized that views won’t accept subquerys, which

How to add value to SET field in mysql?

I have a table named user with a field of type SET named privs. The allowed values of this field are: ‘ADD’,’EDIT’,DELETE’,’ALL’. What SQL query should I execute to add let’s say value ‘EDIT’ to the field privs for a given row? But only if there is not already such a value. EDIT: I tried: update user set privs=concat(privs,’EDIT’) But

Calculating a Moving Average MySQL?

Good Day, I am using the following code to calculate the 9 Day Moving average. But it does not work because it first calculates all of the returned fields before the limit is called. In other words it will calculate all the closes before or equal to that date, and not just the last 9. So I need to calculate

Advertisement