|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Transposing a table (sub items)
This may be a naive question, and I have found a way to work around the problem, but I'd like to do this right, and I"m curious. Note also that I'm a beginner.
There is a bit of background to this question, and I can answer that if there is interest, but it boils down to this. I have a table like the following: (equipment inventory items) (sorry can't seem to insert a Tab)ID:Tag:Ref a : j1 b : j2 c : k1 : a d : k2 : a Where items "c" and "d" are sub items of "a". Because I don't have access to make tables, and running multiple queries is really slow in this case (I'm using MS Access through ODBC), I'm trying to list all the inventory items with Tag "j*" but include their sub items. So I want something like this: ID : Tag : Ref : Sub1 : Sub2 : Sub3 a : j1 : c : d b : j2 I'm willing to say that there won't be more than n sub items (say n=4) I think some of my speed problems come from the fact that the Ref column is not indexed, making the following query kind of slow (1-2 seconds) Not to mention the fact that I'm doing it in MS Access over ODBC connections. SELECT tbl.id, tbl.tag, tbl.ref, tbl2.tag AS Sub1 FROM tbl INNER JOIN tbl AS tbl2 ON tbl.id=tbl2.ref Is there a convenient way to do this without having to make tables in the database? Maybe I'm thinking about it all wrong, and there is an easy way, but I haven't been able to find it. Any help will be appreciated. Thanks |
|
#2
|
||||
|
||||
|
Solution from Quest (might be a bit overkill)
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Transposing a table (sub items) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|