Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Query using 2 tables

Posted on 2007-11-16
4
Medium Priority
?
178 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 1500 total points
ID: 20495518
I can't see where the DISTINCT operator figures in the solution at all
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

705 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