473,795 Members | 3,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query references same column twice

I have looked around and can't find any help for my SQL problem.

I have a Table which lists people
peopledb.
_____________
id | Name
1 | Fred
2 | Bill
3 | Bob

And a second table which references two people from the first

Partnershipsdb
____________
id | Pship1 | Pship2
1 1 2
2 1 3

I would Like to make a query which Lists both names in each
Partnership.

Result should be
Fred | Bill
Fred | Bob

I've tried queries with Select as, and am having trouble with how to go
about referencing the same column in the peopledb twice.

Any help appreciatted.

Vol

Dec 4 '06 #1
2 7711

Volition wrote:
I have looked around and can't find any help for my SQL problem.

I have a Table which lists people
peopledb.
_____________
id | Name
1 | Fred
2 | Bill
3 | Bob

And a second table which references two people from the first

Partnershipsdb
____________
id | Pship1 | Pship2
1 1 2
2 1 3

I would Like to make a query which Lists both names in each
Partnership.

Result should be
Fred | Bill
Fred | Bob

I've tried queries with Select as, and am having trouble with how to go
about referencing the same column in the peopledb twice.

Any help appreciatted.

Vol
SELECT * FROM tablea AS a
LEFT JOIN tableb AS t1 ON t1.id = a.column2
LEFT JOIN tableb AS t2 ON t2.id = a.column3
ORDER BY a.column1

Dec 4 '06 #2

strawberry wrote:
Volition wrote:
I have looked around and can't find any help for my SQL problem.

I have a Table which lists people
peopledb.
_____________
id | Name
1 | Fred
2 | Bill
3 | Bob

And a second table which references two people from the first

Partnershipsdb
____________
id | Pship1 | Pship2
1 1 2
2 1 3

I would Like to make a query which Lists both names in each
Partnership.

Result should be
Fred | Bill
Fred | Bob

I've tried queries with Select as, and am having trouble with how to go
about referencing the same column in the peopledb twice.

Any help appreciatted.

Vol

SELECT * FROM tablea AS a
LEFT JOIN tableb AS t1 ON t1.id = a.column2
LEFT JOIN tableb AS t2 ON t2.id = a.column3
ORDER BY a.column1
Strawberry,

I tend to not give out full answers to such simple cases - it looks too
much like someones class/homework. If he can't find the answer using
google - he really should find another line of work.

Dec 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4235
by: Jason | last post by:
I will explain (or at least try to) first and then give an example after. I need to append a number of rows from several tables into one master table. Unfortunately there are certain columns (which are UNIQUE columns in the master table) in the source tables that are repeated in the same table or across the source tables. Example: Source 1 Source 2
1
1246
by: Silvio | last post by:
Hey guys, Here's my situation: I have a table called lets say 'Tree', as illustred bellow: Tree ==== TreeId (integer)(identity) not null L1(integer)
2
1581
by: sk | last post by:
I have a table for storing alerts (exceptional situations) occuring on devices that I monitor. Associated with each alert is an alert code, a description, the device responsible for causing the alert, when the alert was generated, and when the alert was removed (device no longer had the alert) A candidate table definition looks like CREATE TABLE Alerts ( device_id varchar(17),
6
1710
by: Rory Campbell-Lange | last post by:
The following query on some small datasets takes over a second to run. I'd be grateful for some help in understanding the explain output, and to remake the code. Looks like the sort is using up quite a bit of resources. I made an index on boards using columns "b.n_type, b.n_id, b.t_name" but the index was not recorded in explain analyze. (see "testindex" below). I am using PostgreSQL 7.4.2 on i386-pc-linux-gnu (Debian). The query is...
1
1531
by: Chris Smith | last post by:
I've just noticed in the regular profiling information from our web application that a particular query on a fairly small database is taking about 15 seconds. The query is generated from software on the fly, hence its quirkiness -- if any of that is the problem, then I'll go ahead and fix it, but I can't imagine a few repeated WHERE conditions fooling the query optimizer. Anyway, I don't know how to interpret query plans. Can anyone...
6
4851
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID SalesManName AT Alan Time
6
6543
by: blue875 | last post by:
A tale of two queries: One query looks like this, and runs fine. We'll call this the "Customer1 query": SELECT Customer1 overall.*, IIf(IsNull(.),0,1) AS IsField, IIf(IsNull(.),0,1) AS IsStaff FROM ( LEFT JOIN ON .=.) LEFT JOIN
22
31213
by: Stan | last post by:
I am working with Access 2003 on a computer running XP. I am new at using Access. I have a Db with a date field stored as mm/dd/yyyy. I need a Query that will prompt for the month, ie. 6 for June, and will return all records in that month.
10
2722
by: darkenroyce | last post by:
Hi Guys I am creating a sports database and one of the features involves create drop down dialogue boxes that retrieve data from MySQL tables and provides them as <option> within <select></select>. I am using PHP for this and I'm fairly new at the programming language. I have got the dialogue to work with respect to retrieving the data from MySQL table but it only displays the data from first row/first column of the table twice. I want the...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.