08 Php Mysql Complex Queries Functions

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    08 Php Mysql Complex Queries Functions - Presentation Transcript

    1. PHP Day 08 Geshan Manandhar Developer, Young Innovations Private Limited www.geshanmanandhar.com/slides/php http://www.php.net http://www.mysql.com
    2. MYSQL queries
      • MYSQL query with sorting ASC and DESC
      • MYSQL query with limit and offset
      • MYSQL query with join 2 tables
      • MYSQL query with count, sum, avg, min
      • MYSQL query with string concat
      • MYSQL query with like % and _
    3. tbl_user_test schema
    4. tbl_test_user instance/data
    5. Sorting With MYSQL
      • SELECT tu.user_id, tu.user_login, tu.email FROM tbl_user_test AS tu ORDER BY tu.user_login ASC ;
      • SELECT tu.user_id, tu.user_login, tu.email FROM tbl_user_test as tu ORDER BY tu.email DESC ;
      • ASC – Ascending taken by default.
    6. Limit in MYSQL
      • SELECT * FROM `tbl_user_test` LIMIT 1 ; - select only one row.
      • SELECT * FROM `tbl_user_test` LIMIT 1,3 ; - Select 2 nd row and 3 rows including 2 nd row.
        • Good to use for pagination
    7. Table joins with MYSQL
      • SELECT tu.user_login, tl.log_text FROM tbl_user_test AS tu, tbl_log AS tl WHERE tu.user_id = tl.tbl_user_test_user_id;
    8. Calculations with MYSQL
      • SELECT MIN( tp.price ) FROM tbl_products AS tp; - Applicable of single column
      • SELECT tp.type, MIN( tp.price ) FROM tbl_products AS tp GROUP BY tp.type; - simple group by.
      • SELECT COUNT( * ) FROM tbl_products; - single column
      • SELECT tp.type, COUNT( tp.name ) FROM tbl_products AS tp GROUP BY tp.type;
    9. Sum and Average
      • SELECT SUM ( tp.price ) FROM tbl_products AS tp;
      • SELECT tp.type, SUM (tp.price) FROM tbl_products AS tp GROUP BY tp.type;
      • SELECT AVG ( tp.price ) FROM tbl_products AS tp;
      • SELECT tp.type, AVG (tp.price) FROM tbl_products AS tp GROUP BY tp.type;
    10. String Concat
      • SELECT CONCAT(tc.first_name, ' ', tc.middle_name, ' ', tc.last_name) AS FullName FROM tbl_client AS tc;
    11. CONCAT_WS
      • SELECT CONCAT_WS(' ', tc.first_name, tc.middle_name, tc.last_name) AS FullName FROM tbl_client AS tc;
    12. Select for searches
      • SELECT * FROM `tbl_user_test` WHERE user_login LIKE 'user%' ;
      • %: Matches any number of characters, even zero characters.
    13. Select for searches
      • SELECT * FROM `tbl_user_test` WHERE user_login LIKE 'user_' ;
      • _: Matches exactly one character.
    14. Questions
    15. Lets run some SQL queries
      • Show users in ascending and descending order as per user_login.
      • Show users of row 2-5 in ascending order as per email.
      • Show maximum price from tbl_products grouped by type.
      • Experiment concat and search queries…

    + Geshan ManandharGeshan Manandhar, 5 months ago

    custom

    624 views, 1 favs, 0 embeds more stats

    Complex MYSQL queries from PHP

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 624
      • 624 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags