Solved

Query using 2 tables

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Chat Room 1 43
Restrict result set 1 33
What is Thread.Sleep? 5 45
ADO.NET ENTITY DATA MODEL 3 30
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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 shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

932 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

10 Experts available now in Live!

Get 1:1 Help Now