Solved

MySQL Query help

Posted on 2011-02-21
4
273 Views
Last Modified: 2012-05-11
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
Comment
Question by:BrianFord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 34945305
Select *, (select name from table b where b.id = a.id) from a
0
 

Author Comment

by:BrianFord
ID: 34945348
sorry, doesn't work: sub-query returns more than 1 row
0
 
LVL 39

Accepted Solution

by:
Aaron Tomosky earned 250 total points
ID: 34945404
If all the names in table b for that Id are the same just wrap  name in a max function
Max(name)
0
 

Author Closing Comment

by:BrianFord
ID: 34945632
Thanks very much,

Looks like this will work fine for me :)
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question