I want to get data from multiple table in to one list. And I don't know how to do it.
Please help me with a detail example.
Content Query WebPart is a good solution, but since you are using SharePoint 2013, you can use SharePoint 2013 new feature Content Search WebPart, this is also very good. Following are the steps to achieve the goal:
I have couple of lists in the SharePoint, I need top show them in webpart in list format.
I have four lists in the site, they are List1, List2, List3 and List4. The data in the lists are as follows:
Now I need to show them in list format all data. Following are the steps:
contentclass:STS_ListItem AND (path:http://SiteURL/sites/hub/Lists/List1 OR path:http://SiteURL/sites/hub/Lists/List2 OR path:http://SiteURL/sites/hub/Lists/List3 OR path:http://SiteURL/sites/hub/Lists/List4)
Exlanation of the Query: First Part--> contentclass:STS_ListItem --> depicts the result's content type must be ListItem. Second Part--> path --> depicts where from the data should be retrieved. Since I am fetching the data from 4 lists, I have put 4 lists name in OR format.
- Click OK
- Change the Display template of the Item to Two Lines
- Click OK button
- Save the Page. Following will be the results:
You can see all the data is coming from the 4 different list List1, List2, List3 and List4. The above process will create a simple view. If you want to change the view, you can do it very easily by editing the Display template HTML of the Content Search Webpart, which is saved in the Site Settings > Master pages and page layouts > Display Templates > Content WebPart. If you want to introduce any custom column in the Search Result, you can do it by adding that column as Managed Property and adding it in the Display Template.
There two detail article which will show with screen how to do it:
You can use SPSiteDataQuery Class. This class allows you to fetch data from multiple lists by querying against them.