• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • 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 ?
0
BrianFord
Asked:
BrianFord
  • 2
  • 2
1 Solution
 
Aaron TomoskySD-WAN SimplifiedCommented:
Select *, (select name from table b where b.id = a.id) from a
0
 
BrianFordAuthor Commented:
sorry, doesn't work: sub-query returns more than 1 row
0
 
Aaron TomoskySD-WAN SimplifiedCommented:
If all the names in table b for that Id are the same just wrap  name in a max function
Max(name)
0
 
BrianFordAuthor Commented:
Thanks very much,

Looks like this will work fine for me :)
0
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

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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