Quantcast
Viewing all articles
Browse latest Browse all 207

Optimization : JOIN or CTE

Suppose that I have these tables,and example data (the real table I am working on has more columns)

table `users`

idnamezip
1John201

table `region`

zipcitystatecountry
22abc

table `purchase`

iduser_idprice
232

Should I use subquery,cte or join when those tables have billions of records (so efficiency matters) and

  1. query which city,state,country does the user id=1 lives (Yield 1 row)
  2. query the name, city, price of a purchase order by price desc limit 100 (Get details on top 100 purchases).
  3. query the number of the purchases, sum of price of users whose name begins with "Dr"
  4. query the average spending(sum of price) of users in each city in country "c"

Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>