Monday, February 20, 2012

Query Assistance Needed - Please

Alright, I have this table called Tags. The three columns of interest
are Tags.Id, Tags.Name, Tags.ParentTagId

This is the query I am currently using:

Select Tags.Id, Tags.Name, Tags.ParentTagId

Quote:

Originally Posted by

>From Tags


WHERE Tags.Id IN (
22536,
22535
)

This outputs to:

Id Name ParentTagId
-- ---- -----
22535 Courses 148
22536 AEB3300-2204 22535

Obviously, Courses is the Parent Tag Name to AEB3300-2204. How can I
get this to show up so the results are something like

Id Name ParentTagId ParentTagName
-- ---- -----
-----
22535 Courses 148 SomeName
22536 AEB3300-2204 22535 Courses

Thank you all for your help! I truly appreciate it!Hi there,

I think this would work:

===========================================
select T1.id, T1.name, T1.ParentTagId, T2.Name As ParentTagName
fromTags T1,
Tags T2
whereT1.ParentTagId = t2.Id
===========================================

Thanks,

Marc

Andrew Tatum wrote:

Quote:

Originally Posted by

Alright, I have this table called Tags. The three columns of interest
are Tags.Id, Tags.Name, Tags.ParentTagId
>
This is the query I am currently using:
>
Select Tags.Id, Tags.Name, Tags.ParentTagId

Quote:

Originally Posted by

From Tags


WHERE Tags.Id IN (
22536,
22535
)
>
This outputs to:
>
Id Name ParentTagId
-- ---- -----
22535 Courses 148
22536 AEB3300-2204 22535
>
Obviously, Courses is the Parent Tag Name to AEB3300-2204. How can I
get this to show up so the results are something like
>
Id Name ParentTagId ParentTagName
-- ---- -----
-----
22535 Courses 148 SomeName
22536 AEB3300-2204 22535 Courses
>
Thank you all for your help! I truly appreciate it!

|||You should get a copy of TREES & HIERARCHIES IN SQL for other ways to
mode this in SQL.

No comments:

Post a Comment