Solved

Query using 2 tables

Posted on 2007-11-16
4
167 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this article I will describe the Copy Database Wizard 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.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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.

746 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

13 Experts available now in Live!

Get 1:1 Help Now