Distinct-Limit-Orderby-AndOr In database Concepts and Some Query Tips


LITTLE BIT DATABASE
         If you want to run multiple queries, use semicolon (;) at the end of the query.
             Try to use capital letters for "SELECT" "FROM" keywords. It is nice to use for a good programmer. 



          DISTINCT: (SELECT DISTINCT city FROM customers.
                 Distinct keyword returns every row only one time for each value.

              LIMIT: It limits your results. 
                     If you want to show first five results, all you need to do is typing "LIMIT 5" at the end.
                         If you type "LIMIT 5,10"
                                  It retrieved ten pieces of data starting from 5 (5, 6, 7, ...15)
                                    First number is starting point
                                      Second number is amount of data


                              ORDER BY: used at the end of query.
                                     SELECT name, city FROM customer_all ORDER BY city, name
                                              It orders first by city alphabetically 
                                                and then if there are more then one customer which lives in same city, so it will order by name. 
                                                       This is next criteria to sort the results
                                                         you can have more option to order data numerically or dictionary sorting.
                                                        DESC Sort the results from high to low or Z to A. (Z-A: descent dictionary sorting)
                                                                Q.To find higher id number;
                                                                        SELECT id FROM customers ORDER BY id DESC


                                                      AND: All of the tests must be true.
                                                      OR:  Only one of them need to be true.
                                                        1. Q: We want all customer' city, name and id number whose id is 1 or 2 and live in Istanbul?
                                                                   SELECT city, name, id FROM customers WHERE (id=1 or id=2) and city='Istanbul'
                                                                                 Please make sure that you use paranthesis, because it returns different results!

                                                               IN: Instead of using 3 OR statements we can use IN keywords.
                                                                         SELECT * FROM customer_all WHERE id IN (3, 5, 127, 1346) ORDER BY id

                                                            For more click here

                                                            Ercan Duman
                                                            ercanduman30@gmail.com
                                                            admin@laranargilemalzemeleri.com 

                                                            Comments

                                                            Popular posts from this blog

                                                            Gove confirms mandatory housebuilding targets for councils will be abolished in face of Tory rebellion – UK politics live

                                                            Kotak Mahindra Bank Recruitment 2022 Released for Graduate Candidates And Apply Online