Next lets apply GROUP BY clause to the above resultset: select d1.id,d1.product,count(d1.product)Īnd the last step is to apply HAVING count(.) 2 select d1.id,d1.product,count(d1.product) In this case there are 4 records that meet the join condition: product1, product2, product3 and product4.Ī partial resultset for 4th record from d1 is: | ID | Product | ID | Product |Īnd the whole resultset of the query is: | ID | Product | ID | Product | Then the query takes the last record from d1 - product4. In this case there are 3 records that meet the join condition: product1, product2 and product3.Ī partial resultset for 3rd record from d1 is: | ID | Product | ID | Product | Then the query takes the next record from d1 - product3. In this case there are 2 records that meet the join condition: product1 and product2.Ī partial resultset for 2nd record from d1 is: | ID | Product | ID | Product | Then the query takes the next record from d1 - product2. So a partial resultset for 1st record from d1 is: | ID | Product | ID | Product | It takes a first record from the left table (d1), then searches through the right table (d2) and pick from the right table all records that meet the join condition.įor the record with product1 (d1 table) there is only one record from d2 table that meets the condition: d1.product>=d2.product - just product1. On d1.id=d2.id AND d1.product>=d2.product The first evaluated part of the query is a join: select * To understand how it works, just debug the query, step by step, but using a smaller data set
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |