Solved

MySQL Query help

Posted on 2011-02-21
4
268 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

25 Experts available now in Live!

Get 1:1 Help Now