DC Web Makers Blogs & News

15 Tricks That Any Serious MySQL Database Developer Should Know (Part 2)

Continuing from Part 1:

6. DATE_FORMAT Function
To deliver more professional applications, you should use the MyS...

Continuing from Part 1:

6. DATE_FORMAT Function
To deliver more professional applications, you should use the MySQL DATE_FORMAT function wherever needed.

7. IN() Versus BETWEEN ... AND ...
IN() is mainly used for a few options, whereas BETWEEN is used for a range of values as seen in below queries:
"SELECT * FROM user WHERE age=15 AND age=16 AND age=17"
or
"SELECT * FROM user WHERE age IN (15,16,17) "
or
"SELECT * FROM user WHERE age BETWEEN 15 AND 17"

8. IS NULL or IS NOT NULL
When you want to filter a null or valid values, use the "IS NULL" and "IS NOT NULL" functions respectively. For instance, below, the query returns all users who have the null value for their age:
"SELECT * FROM user WHERE age IS NULL"

9. ORDER BY DESC, ASC, RAND()
It is self-explanatory.

10. LIMIT A, B
It is better to use LIMIT in conjunction with ORDER BY. The LIMIT A, B means start from the row number A and take out B number of rows. Then, return the result set. It is a great tool for a large-scale application (to unload the MySQL processing task), application paginations, and search queries, so make sure to use it.

Stay Tuned for Part 3.....

DC Web Makers Blogs
15 Tricks MySQL Developer (Part 2)

Blog & News Details

15 Tricks That Any Serious MySQL Database Developer Should Know (Part 2)

  • Posted: Tuesday February 19th
  • Continuing from Part 1:

    6. DATE_FORMAT Function
    To deliver more professional applications, you should use the MySQL DATE_FORMAT function wherever needed.

    7. IN() Versus BETWEEN ... AND ...
    IN() is mainly used for a few options, whereas BETWEEN is used for a range of values as seen in below queries:
    "SELECT * FROM user WHERE age=15 AND age=16 AND age=17"
    or
    "SELECT * FROM user WHERE age IN (15,16,17) "
    or
    "SELECT * FROM user WHERE age BETWEEN 15 AND 17"

    8. IS NULL or IS NOT NULL
    When you want to filter a null or valid values, use the "IS NULL" and "IS NOT NULL" functions respectively. For instance, below, the query returns all users who have the null value for their age:
    "SELECT * FROM user WHERE age IS NULL"

    9. ORDER BY DESC, ASC, RAND()
    It is self-explanatory.

    10. LIMIT A, B
    It is better to use LIMIT in conjunction with ORDER BY. The LIMIT A, B means start from the row number A and take out B number of rows. Then, return the result set. It is a great tool for a large-scale application (to unload the MySQL processing task), application paginations, and search queries, so make sure to use it.

    Stay Tuned for Part 3.....