Mysql select distinct

DISTINCT is not a function that applies only to some columns. It’s a query modifier that applies to all columns in the select-list. That is, DISTINCT reduces rows only if all columns are identical to the columns of another row. DISTINCT must follow immediately after SELECT (along with other query modifiers, like SQL_CALC_FOUND_ROWS). Then following … Read more

Selecting first and last values in a group

If you are using MySQL 8, the preferable solution would make use of the window functions FIRST_VALUE() and/or LAST_VALUE(), which are now available. Please have a look at Lukas Eder’s answer. But if you’re using an older version of MySQL, those functions are not supported. You have to simulate them using some kind of workarounds, … Read more

MySQL – DATE_ADD month interval

DATE_ADD works just fine with different months. The problem is that you are adding six months to 2001-01-01 and July 1st is supposed to be there. This is what you want to do: SELECT * FROM mydb WHERE creationdate BETWEEN “2011-01-01” AND DATE_ADD(“2011-01-01”, INTERVAL 6 MONTH) – INTERVAL 1 DAY GROUP BY MONTH(creationdate) OR SELECT … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)