Link to home
Start Free TrialLog in
Avatar of coyotee
coyotee

asked on

JOIN Query that returns only the first record from every joined second table

Hi!

Here's my problem: I have two tables.

Table1:

recID       Description
a             record a
b             record b
c             record c
d             record d

Table2:
recID       Table1RecID       Description
1             a                       Record 1
2             a                       Record 2
3             a                       Record 3
4             b                       Record 4
5             b                       Record 5

I would like to make a left join query, that would return ONLY ONE (can be random) record for every TABLE1 record FROM TABLE 2. Example:

recIDTable1         RecIDTable2        DescTable2
a                         2                       Record2
b                         4                       Record4
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

Try this!

Select Top  1 Table1 .recID,   Table2.RecID,  Table2.Desc From Table1, Table2
order by newid() --this for random
ASKER CERTIFIED SOLUTION
Avatar of Otana
Otana

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial