TRIM() string function in MySQL – with examples.

In this post, I’ll cover examples of the MySQL TRIM() function. TRIM() removes specific characters – or spaces – from a given string, at either: the beginning, ending, or potentially in both locations depending on several factors. With an optional keyword argument that controls which character(s) – if any – are removed, TRIM() can be tricky so let’s gain understanding with several easy-to-digest examples…

[Keep reading for more MySQL database and Python/PHP-centric content >>>]
Advertisements

Sorting associative arrays in PHP with array_multisort() – New learning

If you write MySQL queries, at some point you are going to have to provide query results in a specific order. To impose any ordering in MySQL (this applies to SQL overall and is not directed only at MySQL), you have to use the ORDER BY clause. Without it, there is no guaranteed order. The database is free to send back query results in any order. As I learn PHP, I make it a point to explore both the MySQL side, along with the PHP side in regards to similar type tasks and the efficiency of each. So far in my PHP journey, I have found that arrays are used quite extensively. In this post, I’ll cover array_multisort() – one of many in-built PHP functions – used for sorting arrays. In the context of the example data for this post, the arrays are populated by an unordered MySQL query. Let’s see one example of how you can establish a sorting order in a PHP array, that is populated from an unordered MySQL query…

[Keep reading for more SQL database and Python/PHP-centric content >>>]

Exploring .count() and COUNT() – MySQL Shell Python mode

Retrieving a table count of rows using the COUNT(*) aggregate function in MySQL is a straight-forward query. What if I told you that with the MySQL Shell, there are actually 3 possible ways – between 2 Shell modes (\sql and \py) – to retrieve a table row count? Would you be interested in knowing about them? Honestly, one of the queries will not surprise you in the least bit, as you are likely already using it. However, the other 2 queries – in this context – are specific to MySQL Shell Python mode. You can likely execute these queries in Javascript Mode. However, I am not versed in Javascript programming nor MySQL Shell Javascript mode so those queries are not covered here. Continue reading to see the example queries in Python mode…

[Keep reading for more MySQL database and Python/PHP-centric content >>>]

Pivot query in MySQL – Learning by example.

While reading in a fantastic SQL book I frequent quite a bit, I discovered a type of query in one of the examples that I really should know. For a better learning experience, in order to solidly the concepts presented, I applied them to some data that I am familiar with. The topic: pivoting rows of data. Although I am aware of this data presentation, I have never studied a pivot query. ‘So why not learn it then’ I thought to myself. Are you interested in learning about a pivot query also? Continue reading and see an easy-to-comprehend example…

[Keep reading for more MySQL database and Python/PHP-centric content >>>]

Column meta-data in MySQL Shell with Python mode

Meta-data is important to SQL DBA’s and Developers, likely for different reasons. There are all sorts of ways to access meta-data. The powerful MySQL Shell in Python mode is no exception. What if you need the column meta-data on a result set? You can use the get_columns() method and obtain useful meta-data information about it (the result set). All in Python mode. Continue reading to see examples…

[Keep reading for more MySQL database and Python/PHP-centric content >>>]