Solved

Query using 2 tables

Posted on 2007-11-16
4
176 Views
Last Modified: 2010-04-15
How to write a query to select 3 columns from 2 different tables?
For example there is USERID ,PRODUCTID in table A, and ID (which holds the same value as ProductID in tableA),ProductName in a table b.Now I want to show that this particular user  is having specific productid and product name.
0
Comment
Question by:onebite2
[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
4 Comments
 
LVL 5

Expert Comment

by:gigglick
ID: 20299431
select distinct USERID , PRODUCTID ,ProductName  from tableA inner join tableB on tableA.PRODUCTID  = tableB.ID

for a specific USERID:
select distinct USERID , PRODUCTID ,ProductName  from tableA inner join tableB on tableA.PRODUCTID  = tableB.ID where USERID = theuserid
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20324894
you can prefix the columns based on which table they came from, i.e.

select TableA.USERID, TableA.PRODUCTID, TableB.ID, TableB.ProductName
from TableA
 inner join TableB on TableA.PRODUCTID = TableB.ID
0
 
LVL 25

Accepted Solution

by:
imitchie earned 500 total points
ID: 20495518
I can't see where the DISTINCT operator figures in the solution at all
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

631 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