Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

select distinct and left join

select distinct and left join

select distinct and left join


I have 2 tables, for example:
table1 with columns: id - agentid
with values:
1 - agent1
2 - agent2
3 - agent3

and table2 with columns id - info
with values:
1 - info 1
1 - info 2
1 - info x
2 - info y

Is it possible to display all the values from tabel1 and the info from tabel2 (but without the duplicate id's?)

id - agent - info with values:
1 - agent1 - info 1 (or info2, or info3)
2 - agent2 - info y
3 - agent3 - /

I tried the left join query...
SELECT table1.id, table1.agentid, table2.info
FROM table1 LEFT JOIN table2 ON
table1.id = table2.id

but as expected, this shows id 1 3 time (with info1, info2 and info3).  I tried SELECT distinct(table1.id), ... but this doesn't work.

Any help is appreciated
Replies continue below

Recommended for you

RE: select distinct and left join

PHV, thanks for the reply.

I used the following
1) create a query with DISTINCT with the unique ID's
2) create a query and display the ID's from the first query (the unique ID's) and the info from the other tables (agentid + info).  Using a left join...

I'll check the MIN() function.  Thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close