Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 complex select query

Author  Topic 

attackmonkey
Starting Member

19 Posts

Posted - 2003-04-29 : 07:14:00
I haven't got my sql head on today. I'm implementing a system of linked content on one of our sites, something which I'd normally have no problem with, but for some reason I just can't get this to work today.

:(

I have two tables, tbl_sections, which holds a list of all the sections, and tbl_templates_linked which holds all the linked data. The relevant columns in this table are tl_sid, which is the section that the links belong to in the tbl_sections table, and tl_link_id which is the id in tbl_sections that I am linking to.

On the page in my app where I am listing out the linked content, I need to list out all the content in the system, and two columns from the second table, to show whether it's being linked to, and what the display order is. This is the query I'm using:

SELECT tbl_sections.*, tbl_template_links.tl_link_id, tbl_template_links.tl_order FROM tbl_sections LEFT OUTER JOIN
tbl_template_links ON tbl_sections.section_id = tbl_template_links.tl_link_id WHERE tbl_sections.section_special = 0) AND (tbl_template_links.tl_sid = '{3C290627-5D5B-43F9-B1C2-A34630A72589}' OR tbl_template_links.tl_sid IS NULL) OR (tbl_sections.section_special = 1) ORDER BY tbl_sections.section_order, tbl_sections.section_title

I would expect to get all of the sections, and then if the columns match, then the last two columns would have values in. However, If a
different section to the one I'm editing is linked to one of the sections, then it doesn't show up anywhere else. I'm sure it's something pretty obvious that I've missed, can anyone help?

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-04-29 : 08:06:26
Can you post your dml.

CREATE TABLE etc.....

and some sample data.

val1, val2, val3...

and expected results

x1,x2,x3....etc...

Go to Top of Page

attackmonkey
Starting Member

19 Posts

Posted - 2003-04-29 : 08:20:44
It's ok, I found a way round it. I'm using a subquery as part of the main query now, and it seems much happier! :)

Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-04-29 : 08:22:23
You should still post what you're doing maybe someone can help you optimize.

Go to Top of Page
   

- Advertisement -