Blog Archives

Store compressed data in database using PHP

When storing big text contents in a database, it is better to store after compressing the data. The following is an example storing HTML contents in a database cache. We first create a table mapping URLs to HTML contents. The

Tagged with: , ,
Posted in PHP, SQL

Update Two Tables with Joins in MySQL

Here we show an example of updating two table at the same time using joins. Suppose we have two tables: lookup which holds information on a person, and activity which holds certain activities happening on a person. Imagine that lookup

Tagged with: ,
Posted in MySQL, SQL

Select Random Records in MySQL

Selecting random records from a table is helpful when showing items with no preferences or testing different result sets. The following SQL defines a table holding images. Imagine that we wish to pick up 10 random rows from it. In

Tagged with: , , ,
Posted in MySQL, SQL

Generate Serial Number in SQL

The next query generates results as below. Suppose we want to add a column with serial numbers, just as below. In MySQL, this can be done by defining a variable in the query: Reference: MySQL User Defined Variables

Tagged with: , , ,
Posted in SQL