It is currently Thu Mar 28, 2024 2:46 am



Reply to topic  [ 7 posts ] 
SQL Question 
Author Message
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 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?

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Fri Feb 16, 2007 9:52 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
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;


Fri Feb 16, 2007 6:57 pm
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
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. :/

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Sat Feb 17, 2007 11:19 am
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
Horizotnal promotion? I think you mean a lateral transfer. A horizontal promotion implies something a little different...


Sat Feb 17, 2007 3:07 pm
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
hrm.....well, it's a promotion where I get paid the same but work harder. Perhaps you'd like to explain your definition?

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Mon Feb 19, 2007 3:45 pm
Profile WWW
Duke
User avatar

Joined: Mon Mar 31, 2003 8:59 am
Posts: 1358
Location: right behind you
Reply with quote
Post 
I have always considered a "horizontal promotion" to be exchanging sexual favors for promotion. But maybe that's just how my mind works.


Tue Feb 20, 2007 1:26 am
Profile YIM WWW
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post 
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.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Tue Feb 20, 2007 7:33 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.