SPSiteDataQuery class is used to retrieve data from multiple lists. Use SPSiteDataQuery object to aggregate data from multiple lists, which obviates the need to enumerate sites and lists.The SPSiteDataQuery class is used to query data from multiple lists across different sites in a site collection. SPSiteDataQuery is commonly used in list aggregation scenarios, where list data from team sites or other subsites is collated and presented in a single interface. Unlike the SPQuery class, you cannot use join predicates or projected fields with the SPSiteDataQuery class. The SPSiteDataQuery will only aggregate data from SharePoint lists and will ignore data from external lists.
Note: Itâ€™s not a best practice to use SPSiteDataQuery instead of that make a use of â€˜forâ€™ or â€˜foreachâ€™ loops to aggregate data.