|
It is currently Thu Nov 21, 2024 1:44 pm
|
|
Page 1 of 1
|
[ 7 posts ] |
|
Author |
Message |
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
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 |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
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 |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
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 |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
Horizotnal promotion? I think you mean a lateral transfer. A horizontal promotion implies something a little different...
|
Sat Feb 17, 2007 3:07 pm |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
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 |
|
|
Pig
Duke
Joined: Mon Mar 31, 2003 8:59 am Posts: 1358 Location: right behind you
|
|
Tue Feb 20, 2007 1:26 am |
|
|
Satis
Felix Rex
Joined: Fri Mar 28, 2003 6:01 pm Posts: 16662 Location: On a slope
|
_________________ 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 |
|
|
|
Page 1 of 1
|
[ 7 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 7 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
|
|