• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

MySQL Query help

I have 2 tables joined by USERID:

TableA contains most of the details I need to select except for the
user's name, which I need to pull fom TableB

The problem is that TableB contains multiple records for each user and therefore when
I use something like:

select a.Col1
      , a.Col2
      , b.name
from TableA a
      , TableB b
where b.userID = a.userID

I get wrong info returned because of the multiple user records in TableB

How can I gt the join to look at DISTINCT values only in TableB ?
  • 2
  • 2
1 Solution
Aaron TomoskyTechnology ConsultantCommented:
Select *, (select name from table b where b.id = a.id) from a
BrianFordAuthor Commented:
sorry, doesn't work: sub-query returns more than 1 row
Aaron TomoskyTechnology ConsultantCommented:
If all the names in table b for that Id are the same just wrap  name in a max function
BrianFordAuthor Commented:
Thanks very much,

Looks like this will work fine for me :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now