ClanKiller.com
http://forums.clankiller.com/

SQL Question
http://forums.clankiller.com/viewtopic.php?f=24&t=2209
Page 1 of 1

Author:  Satis [ Fri Feb 16, 2007 9:52 am ]
Post subject:  SQL Question

ok, I have a sql question. I know this is possible, but am not sure what format the query should take.

I have 2 tables.

table1:
CatID
Name
Description

table2:
SubCatID
Name
Description

I have the CatID and SubCatID and I want to resolve these back to the associated names. I could do two queries, but I'm sure it's possible in one query.

select [Name] FROM table1 WHERE CatID = $CatID;
select [Name] FROM table2 WHERE SubCatID = $SubCatID;

I thought maybe

select a.[Name], b.[Name]
FROM table1 a, table2 b
WHERE a.CatID=$CatID
AND b.SubCatID=$SubCatID

Also tried an OR in the where clause, but no go. Any advice?

Author:  Pig [ Fri Feb 16, 2007 6:57 pm ]
Post subject: 

I would just do two queries since the tables are not joined. There's really no point.

Now if you had CatID in table 2, that is another matter.

table1
id
name
description

table2
id
table1id
name
description

SELECT table1.name AS t1name, table2.name AS t2name FROM table1 LEFT JOIN table2 ON table2.table1id = table1.id WHERE table1.id = 1234;

Author:  Satis [ Sat Feb 17, 2007 11:19 am ]
Post subject: 

hmm...actually there is a relationship like that. Many to 1 from table2 to table 1. Ok, thanks, didn't think about doing it that way. I'll give it a shot on Monday if I get time.

btw...I have a new job now (more horizontal promotions) and now I'm constantly working. :/

Author:  Pig [ Sat Feb 17, 2007 3:07 pm ]
Post subject: 

Horizotnal promotion? I think you mean a lateral transfer. A horizontal promotion implies something a little different...

Author:  Satis [ Mon Feb 19, 2007 3:45 pm ]
Post subject: 

hrm.....well, it's a promotion where I get paid the same but work harder. Perhaps you'd like to explain your definition?

Author:  Pig [ Tue Feb 20, 2007 1:26 am ]
Post subject: 

I have always considered a "horizontal promotion" to be exchanging sexual favors for promotion. But maybe that's just how my mind works.

Author:  Satis [ Tue Feb 20, 2007 7:33 am ]
Post subject: 

lol, ok, I could see how you might think that. In this case, no sexual favors were exchanged. Maybe if there had been I'd be getting paid more.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/