r/learnSQL • u/Sufficient-Loan9565 • 16h ago
Use Case of Views and Materialized Views???
Hi there,
As a beginner of learning sql , I really don't know where the data analysts folks actually use of Views and materialised Views to analyse the real world data. Are people really use this in the real world problems day to day .
Help me to understand where is the real use case of these in the real world problems
3
Upvotes
4
u/0utlawViking 16h ago
Yep, definitely! in real world projects, views are used to simplify complex queries and reuse them without writing the same SQl again.
Materialized view are useful when when you frequently need the same heavy calculations or aggregations, as they store the results and save query time, you'll come across both quite often in data analytics!
3
u/First-Feature-3556 13h ago
Views are also an easy way to provide an "external interface" to data:
You are the developer of software A. Software B (maintained by someone else) regularly needs to read data in your database. As soon as your software A changes its database schema (for example, during a release upgrade), software B breaks.
Solution: You create a view with the data that software B needs. That means you can change the DB schema of software A as you see fit, you just need to adjust the view as well to keep it backwards-compatible.
1
u/Discordbothost 12h ago
Try a dashboard that shows yesterday's sales by store and refreshes before the morning meeting. A materialized view can do that grouping once per refresh instead of for everyone who opens the dashboard. If the same page needs to show refunds as they happen, use a live query for that number. How fresh each number needs to be
1
u/treznor70 10h ago
Another usage of views is to abstract away physical data model changes. Data model changes break people's analytical processes. Using views allows you to make a physical data model change while still presenting the data to the analytics process in the same manner. That allows the analytics processes to change over time as opposed to the same moment as the data model change (or potentially never change, depending on the needs of the organization).