'How to combine two tables data in one result set?
I'm working on one requirement, where I need to extract data from two tables (both are having diff column names), but output from both tables need to be mapped same single output schema.
For example
Table one
t1,t2,t3
Table two
c1,c2,c3
Want to run this type of query
select t1 as o1, t2 as o2, t3 as o3 from one
union all
select c1 as o1, c2 as o2, c3 as o3 from two
How can use this query in spring boot to get data from db (mysql) and map it to final data structure to use it further ? any suggestions please
Solution 1:[1]
If your table has no relation with each other or not have common column name fields then you can't perform union query.
What you have to do is, you can perform two different query then map the data to a DTO model. Check out this blog resource.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zakaria Hossain |
