Welcome Guest, Not a member yet? Register   Sign In
Active Record Join with and or
#2

(This post was last modified: 05-02-2017, 04:58 AM by InsiteFX. Edit Reason: Added Example )

If I remember correct the order_by should be the last statement after the where.

Mysql does group by before order by and you get mixed results not what you expected.

SELECT
    [ALL | DISTINCT | DISTINCTROW ]
      [HIGH_PRIORITY]
      [STRAIGHT_JOIN]
      [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
      [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [FROM table_references
      [PARTITION partition_list]
    [WHERE where_condition]
    [GROUP BY {col_name | expr | position}
      [ASC | DESC], ... [WITH ROLLUP]]
    [HAVING where_condition]
    [ORDER BY {col_name | expr | position}
      [ASC | DESC], ...]
    [LIMIT {[offset,] row_count | row_count OFFSET offset}]
    [PROCEDURE procedure_name(argument_list)]
    [INTO OUTFILE 'file_name'
        [CHARACTER SET charset_name]
        export_options
      | INTO DUMPFILE 'file_name'
      | INTO var_name [, var_name]]
    [FOR UPDATE | LOCK IN SHARE MODE]]


In general, clauses used must be given in exactly the order shown in the syntax description. For example,
a HAVING clause must come after any GROUP BY clause and before any ORDER BY clause. The exception is that
the INTO clause can appear either as shown in the syntax description or immediately following the select_expr list.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Messages In This Thread
Active Record Join with and or - by Marcel - 05-02-2017, 01:55 AM
RE: Active Record Join with and or - by InsiteFX - 05-02-2017, 04:03 AM
RE: Active Record Join with and or - by Marcel - 05-02-2017, 05:50 AM



Theme © iAndrew 2016 - Forum software by © MyBB