Archive for "MySQL"

Dec
10
Conditional order by sorting using two fields in MySQL

Here’s the scenario.

I have two fields in my “listings” table with help of which i wanted to sort (order by) results. First field is “activation_date”. It is the activation date of a listing. Second one is “featured” which stores featured tag for a listing in a value of 1 or 0. Click to continue »

Tags : ,

Feb
16
How to update a mysql table with the count of another table while using like statement

While working on a web links directory i wanted to update categories table’s num_listings column with the count of listings under each category. The category id was stored something like this in listings table: Click to continue »

Tags : , , ,

Oct
06
A few notes on joining a MySQL table to itself to get unique combination of field data

Just a few notes on joining a MySQL table to itself to get unique combination of data stored in its fields.

Suppose we have a MySQL table named `keywords` having fields `word1`, `word2` and `word3`. Once we have got a few records inserted into this table we would want to show all possible combination of keywords stored in those fields. For example, a select query returns a following set of data: Click to continue »

Tags : , , , , , ,

Oct
06
Fixing ‘mysql’ is not recognized as an internal or external command in Windows7

Having WAMP installed when i try to type mysql in my windows command prompt it would give me the following error: Click to continue »

Tags : , , , ,

Jun
30
Calculating difference between two mysql dates in seconds

Here is a quick way to calculate the difference between two mysql dates in number of seconds. In my case, i required to fetch all entries for which the difference between current time stamp and date in a table field would be less than 5 minutes. Click to continue »

Tags : , , , , , ,

May
27
MYSQL custom sorting – order by field value

Yesterday i had a somewhat new (for me ) and different kind of requirement while displaying MySQL result on a page. I had a category menu in which masters and slaves were sorted alphabetically and in ascending order. Click to continue »

Tags : , , , , ,

Apr
14
Full-text search in MySQL

Normally, most of us use “SELECT * FROM table WHERE field1 LIKE ‘%$keyword%’” OR field2 LIKE ‘%$keyword%‘ ..etc” to search our table and get results. This is slow and inefficient approach, as it does return all (too many) rows in which it does find a match for “keyword” without caring for “relevancy” and time. Click to continue »

Tags : , ,

Apr
02
To find mysql recodrs between specific date range based on start date and end date fields

While working on a report generation system i had to perform a query to check whether records exist in ‘reports’ table between a date range received from two form fields “start_date” and “end_date”. To make it more specific i will try to explain it with the help of an example. Click to continue »

Tags : , , , ,

Freelance Jobs