Search code examples
mysqlsqlsqlyog

SQL - Substring and select * at the same time


I need to do a substring of a column, but also pull all of the columns when I do the select. Below is the code that I am trying to use, however it isn't functioning correctly:

SELECT SUBSTRING(column_c, 1, 11) AS dateMoved, *
                FROM prostock_movement_header 
                WHERE column_a = '74' 
                AND column_b = '1372' 
                AND dateMoved = '2019-02-23'

How do I go about doing a SELECT * along with a SUBSTRING() AS ALIAS, in the same statement, so that I retrieve all of the columns along with the ALIAS column.

Or is the only way to manually select every other column by name from the table?

Thanks


Solution

  • Just change the order of the selection

    SELECT *,SUBSTRING(column_c, 1, 11) AS dateMoved
                    FROM prostock_movement_header 
                    WHERE column_a = '74' 
                    AND column_b = '1372' 
                    AND SUBSTRING(column_c, 1, 11) = '2019-02-23'