I have three tables:
Table 1:
pid, name, address
1 Dale BLANK
Table 2:
pid, moid
1 12
Table 3:
moid, address
12 123 Main
12 12 South
12 99 North
For output I need:
Table 1:
pid, name, address
1 Dawn 123 Mian,12 South,99 North
How can I combine multiple addresses in table 3 into one address field in table 1 linking the two tables with information in table 2?
You did not specify what RDBMS you are using. In MySQL you can use
GROUP_CONCAT():See SQL Fiddle with Demo
Edit #1, if you want to
UPDATEthe table with this result, then theUPDATEstatement will look like this:See SQL Fiddle with Demo
If you are using Oracle 11g+, then you can use the
ListAgg()function:See SQL Fiddle with Demo
In SQL Server you can use
FOR XML PATHto get the result:See SQL Fiddle with Demo
All of these produce the result: