In what order are MySQL JOINs evaluated?

USING (fieldname) is a shorthand way of saying ON table1.fieldname = table2.fieldname. SQL doesn’t define the ‘order’ in which JOINS are done because it is not the nature of the language. Obviously an order has to be specified in the statement, but an INNER JOIN can be considered commutative: you can list them in any … Read more

Is there a performance hit using decimal data types (MySQL / Postgres)

Pavel has it quite right, I’d just like to explain a little. Presuming that you mean a performance impact as compared to floating point, or fixed-point-offset integer (i.e. storing thousandsths of a cent as an integer): Yes, there is very much a performance impact. PostgreSQL, and by the sounds of things MySQL, store DECIMAL / … Read more

MySQL limit from descending order

No, you shouldn’t do this. Without an ORDER BY clause you shouldn’t rely on the order of the results being the same from query to query. It might work nicely during testing but the order is indeterminate and could break later. Use an order by. SELECT * FROM table1 ORDER BY id LIMIT 5 By … Read more

Generating Depth based tree from Hierarchical Data in MySQL (no CTEs)

You can do it in a single call from php to mysql if you use a stored procedure: Example calls mysql> call category_hier(1); +——–+—————+—————+———————-+——-+ | cat_id | category_name | parent_cat_id | parent_category_name | depth | +——–+—————+—————+———————-+——-+ | 1 | Location | NULL | NULL | 0 | | 3 | USA | 1 | Location … Read more

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