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.
| Author |
Topic |
|
amodi
Yak Posting Veteran
83 Posts |
Posted - 2009-07-23 : 08:41:47
|
| Hello Friends,I had one table with three columns 1. MenuId (auto Increment )2. MenuName3. BelongsTo ( will be the Id of first column “MenuId” )I took the whole table to dynamically create a Menu on a web page. In that I would check for “BelongsTo = Null” for Root Menus and add child nodes using “belongsTo” column. Everything was working fine.Now I divide the Menu’s into 5 tables.1. Menu Table ( will act as an root menu ) 2. Manual table 3. Chapters table4. Topic tables 5. Pages tableNote: all the above tables have id columns that are auto increment.Menus will have manuals and manuals will have chapters and chapters will have topics and topics will have one or more pages.Now how can I merge above tables and get the final result as ID BelongsTo and Name.Thanks |
|
|
craigwg
Posting Yak Master
154 Posts |
Posted - 2009-07-23 : 11:23:24
|
| If I understand your question correctly, it sounds like you will need a query that joins columns from more tables than you will be displaying. Another way to say this is you may be joining 3 tables, but only displaying columns from 2. You did not give table names but it might look something like this:select a.ID, t.BelongsTo, a.Namefrom authors as ajoin titles as t on a.id=t.idjoin books as b on a.id=b.idwhere b.title like '%something%'Notice that the query makes reference to the books table, and even does some row limiting (where statement) with the books table, but no columns from the books table are visible in the select statement. Cool, eh?I hope that helps!CraigCraig Greenwood |
 |
|
|
amodi
Yak Posting Veteran
83 Posts |
Posted - 2009-07-24 : 09:32:21
|
| Thanks craigwg!. |
 |
|
|
|
|
|