The issue I am having is the following:

Table1.FieldA is unique where as the Table2.FieldA field is not.

When I run the following:

SELECT Table1.Numbers, Table2.Numbers
FROM Table1, Table2
WHERE Table1.ID = Table2.ID

I get mutiple records like so:

ID Name Numbers
125 John Doe 555, 556, 557
125 John Doe 686, 687

I know this is happening bc there are multiple records in Table2.ID which match the unique record in Table1.ID

My question is, how can I merge the returned results into one row when I have multiple matches.

Recommended Answers

All 2 Replies

I think you can use join, inner join, left join, right join or cross join,
ex,
select a.numbers,b.numbers
from table1 as a inner join table2 as b on a.id = b.id

Still stuck here. Here is what I have come up with so far:

$query = "SELECT
Table1.*,
Table2.A,
Table2.B,
Table2.C,
Table2.D,
Table2.E
FROM Table1
INNER JOIN
Table2 ON Table1.A = Table2.A

Issue is that there are multiple matches for some instances, like so:

Table1.A value = 1777 (only once since it is a UniqueID)
Table2.A value = 1777 (3 records with this ID value)

So I will get 3 records returned since Table1.A matches 3 records in Table2.A. I want to merge the 3 records in Table2 into 1 record and then match that with Table1 where the UniqueID is the same. Make sense?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.