Solved

MySQL Query help

Posted on 2011-02-21
4
270 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
  • 2
  • 2
4 Comments
 
LVL 38

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 38

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikipedia.org/wiki/PHP  Very powerful.  But a…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

816 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now