473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

question about dependent queries

Suppose I have the following table:

col1 col2
hammet jones
jlo afflect
afflect armand
wills snopt
armand hammet
jones smith

If someone choses armand, then I'd like to return
amand hammet jones smith

The first selection goes over to the second column, gets that value
and locates it back in column one and returns column 2 and so on.

One way of doing it is to set up a separate query for each one and
then construct a new query to get them all.

I'm thinking there's a more elegant way to do this. Any suggestions
would be appreciated.

-David
Jul 20 '05 #1
2 1357
Hi David,

One way is to use the old-fashioned join. Not sure how efficient the
query is though. - Louis

create table #T (x varchar(10),y varchar(10))
insert into #T values ('hammet','jones')
insert into #T values ('jlo','afflect')
insert into #T values ('afflect','armand')
insert into #T values ('wills','snopt')
insert into #T values ('armand','hammet')
insert into #T values ('jones','smith')

select a.x,a.y,b.y,c.y
from #T as a, #T as b, #T as c
where a.x='armand' and a.y=b.x and b.y=c.x

returns:
x y y y
---------- ---------- ---------- ----------
armand hammet jones smith
Jul 20 '05 #2
On 4 Nov 2003 08:29:01 -0800, lo************@hotmail.com (louis
nguyen) wrote:
Hi David,

One way is to use the old-fashioned join. Not sure how efficient the
query is though. - Louis

create table #T (x varchar(10),y varchar(10))
insert into #T values ('hammet','jones')
insert into #T values ('jlo','afflect')
insert into #T values ('afflect','armand')
insert into #T values ('wills','snopt')
insert into #T values ('armand','hammet')
insert into #T values ('jones','smith')

select a.x,a.y,b.y,c.y
from #T as a, #T as b, #T as c
where a.x='armand' and a.y=b.x and b.y=c.x


Lou, thanks. This is what I was looking for and it improved my
understanding of joins.

This is a great forum.

regards,
-David
Jul 20 '05 #3

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

Similar topics

6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
4
by: Lauren Quantrell | last post by:
In my old MDB databases, I constructed a lot of "subQueries" to filter out records, then based a new query on the subQuery. This results in huge speed increases on large datasets. However... In...
6
by: ronwer | last post by:
Hello, The title doesn't completely cover the question I have, but it's a bit more complicated problem we have. We are using a database, based on Acces, but developed by a third party...
3
by: Amadelle | last post by:
Hi All and thanks in advance, I wanted to know when is a good idea to use a static class (with static constructor) and when to use instance classes? I have read couple of articles on line and...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
0
by: Jim M | last post by:
I have an appointment scheduling application with a number of queries that filter through a table with many thousand appointments and comes up with one days schedule. I need to start out by finding...
2
by: cpptutor2000 | last post by:
Could some PHP guru please help me? I am creating a dynamic dropdown list using a code snippet(Section A) as below: Section A: $sql_query=mysql_query("SELECT DISTINCT semester, year from...
4
by: Doris | last post by:
It does not look like my message is posting....if this is a 2nd or 3rd message, please forgive me as I really don't know how this site works. I want to apologize ahead of time for being a novice...
5
by: Christof Warlich | last post by:
Hi, just being curious: Anyone having a clue why the commented lines do not compile? Thanks, Christof class B {
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.