Skip to content

Instantly share code, notes, and snippets.

@mrabbani
Last active November 5, 2019 05:39

Revisions

  1. mrabbani revised this gist Nov 5, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion mysql_tricks.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ## Prority Search
    ## MySql fetch data by conditional order

    Suppose, You want to search product with specified key and the products with stock should appear first in the search result.

    SELECT * FROM `products` WHERE name LIKE 'na%'
  2. mrabbani revised this gist Oct 22, 2018. No changes.
  3. mrabbani revised this gist Oct 22, 2018. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion mysql_tricks.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,9 @@ Suppose, You want to search product with specified key and the products with sto
    ORDER BY CASE
    WHEN id IN (602, 603, 18125) THEN 1
    ELSE 2
    END, name ASC
    END, name ASC

    ## Add Virtual field

    //add p_type as virtual field
    SELECT name, 'mahbub' as p_type from products
  4. mrabbani created this gist Sep 27, 2018.
    8 changes: 8 additions & 0 deletions mysql_tricks.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    ## Prority Search
    Suppose, You want to search product with specified key and the products with stock should appear first in the search result.

    SELECT * FROM `products` WHERE name LIKE 'na%'
    ORDER BY CASE
    WHEN id IN (602, 603, 18125) THEN 1
    ELSE 2
    END, name ASC