SQL for self foreign key has me baffled

Hi guys,
This is probably really simple. I am wanting to write an sql
for a dropdown menu for my top nav in my application. What it is,
is I have one column for ID ( primary ) and another for subID and a
page name ( txt) - seems like it would be simple , but I can't seem
to get it to work.
<cfquery name="getNav2" datasource="#application.db#">
SELECT ID, subID, pagetype, dapage, menuText, title, dasorter
FROM masterPager
ORDER by ID, subID, dasorter, menuText, dapage
</cfquery>
I have tried a where statement ( WHERE ID = subID ) and that
brings up nothing.
There is a diagram of what I want here -
http://www.interaktonline.com/Products/Dreamweaver-Extensions/MXCSSMenus/Documentation/Art icles/Design+Your+Database-Databases+By+Example.html?id_art=24&id_asc=222
( all one line ) They show the table, but not the SQL
The group on the output ( am a little confused )
What I want is for it to look like a tree - then I can apply
my CSS dropdown code.
Home
About Us
About_sub1
About_sub2
Contact
Contact_sub1
Contact_sub2
Products
Products_sub1
Products_sub2
Products_sub3
Disclaimer
Privacy
Any help would surely be appreciated.
Thanks in advance

I'm not sure what database you are using, but assuming SQL
Server, the query below will select all rows and order them either
by their sub_ID, or if the subID is NULL, the ID field would be
used in its place. Items with a NULL subID would be the "primary"
(top level) menu items. This would output your items in the proper
order. In the output, you would group by subID then loop through
and check to see if the ID=subID (which woud indicate the top level
menu items) and the ones following them would be the sub-menu
items.
<cfquery name="getNav2" datasource="#application.db#">
SELECT ID, ISNULL(subID, ID) AS sub_id, pagetype, dapage,
menuText, title, dasorter
FROM masterPager
ORDER by 2, 1, 3, 4, 5, 6
</cfquery>
Phil

Similar Messages

  • [PHP-MYSQL] tutorial on using ADDT and dynamic list/form with self-foreign keys?

    Hi all,
    I have a 3 levels catagoris product catalog and would like to manage it
    using dynamic list/forms.
    I'm searching info about using self-foreign keys on dynamic list/forms.
    Is there any tutorial on how to manage this kind of tables using addt?
    tia
    tony

    Hello Tom,
    You were offered the solution on the InterAKT forums, I am not sure why you are posting this problem again. There's also another thread here that presents the same issue and solution:
    http://www.adobeforums.com/cgi-bin/webx/.3bc42a90/0
    Regards,
    Ionut

  • Syntax for creating foreign key across users in a database

    There are two user present A,B.They are granted all privileges.Now in USER A, there is a table PARENT whose primary key is PARENT_NO.In USER B I have created a table CHILD whose primary key is CHILD_NO.
    In the CHILD table of USER B, I want to create a foreign key relation to the PARENT table of USER A.For this I have created a column CHILD_PARENT_NO in the CHILD table.If anybody knows the syntax please post the syntax for creating the required foreign key relationship?

    Please post your code. Cut'n'paste from SQL*Plus like this...
    SQL> conn a/a
    Connected.
    SQL> desc t1
    Name                                      Null?    Type
    COL1                                               NUMBER
    COL2                                               VARCHAR2(10)
    SQL> grant references on t1 to b;
    Grant succeeded.
    SQL> conn b/b
    SQL> create synonym a_t for a.t1;
    Synonym created.
    SQL> alter table test add constraint fk foreign key (n) references a_t(col1);
    Table altered.
    SQL> Note that Oracle will translate the synonym anyway...
    SQL> select constraint_name, r_owner, r_constraint_name
      2  from  user_constraints
      3  where table_name = 'TEST'
      4  /
    CONSTRAINT_NAME R_OWNER R_CONSTRAINT_NAME
    FK              A       T1_PK
    SQL> By the way, this ...
    GRANT ALL PRIVILEGES TO B;... is a mindbendingly unsafe way of proceeding. In real life you would have given user B the power to utterly destroy your database. It's always easier to start with good habits than to break bad ones so please get used to granting only the minimum set of privileges necessary.
    Cheers, APC

  • How to insert value for composed foreign key?

    My problem when I update or insert to table Ffclient which has link 1-1 with other table ClientLoan by composes primary key loanId and clienId (break table). I auto mapping by Jdeveloper 10g version 10.1.2. In FfClient table has two fields compose foreign key of ClientLoan as loanId and clienId not nullable. In toplink object Ffclient it only has one reference ClientLoan object by clientLoan field, not has two fields loanId and clienId . When I insert or update to database, I can't set value for these two fields direct so I have created new ClientLoan object and set value for composed primary key loanId and clienId, after that set it to object Ffclient. But when I update or insert to database it occurs exception about insert null for two not nullable fields: loanId and clienId.
    Any one has error as mime? Any one help me correct my error.
    Thanks in advance.
    Mapping is:
    ….
    <database-mapping>
    <attribute-name>ffclientCollection</attribute-name>
    <read-only>false</read-only>
    <get-method-name>getFfclientCollection</get-method-name>
    <set-method-name>setFfclientCollection</set-method-name>
    <reference-class>uk.co.lsb.elb.toplink.Ffclient</reference-class>
    <relationship-partner-attribute-name>clientLoan</relationship-partner-attribute-name>
    <is-private-owned>false</is-private-owned>
    <uses-batch-reading>false</uses-batch-reading>
    <indirection-policy>
    <mapping-indirection-policy>
    <type>oracle.toplink.internal.indirection.TransparentIndirectionPolicy</type>
    </mapping-indirection-policy>
    </indirection-policy>
    <container-policy>
    <mapping-container-policy>
    <container-class>oracle.toplink.indirection.IndirectList</container-class>
    <type>oracle.toplink.internal.queryframework.ListContainerPolicy</type>
    </mapping-container-policy>
    </container-policy>
    <source-key-fields>
    <field>LSB.CLIENT_LOAN.CLIENT_ID</field>
    <field>LSB.CLIENT_LOAN.LOAN_ID</field>
    </source-key-fields>
    <target-foreign-key-fields>
    <field>LSB.FFCLIENT.CLIENT_ID</field>
    <field>LSB.FFCLIENT.LOAN_ID</field>
    </target-foreign-key-fields>
    <type>oracle.toplink.mappings.OneToManyMapping</type>
    </database-mapping>
    …..
    <database-mapping>
    <attribute-name>clientLoan</attribute-name>
    <read-only>false</read-only>
    <reference-class>uk.co.lsb.elb.toplink.ClientLoan</reference-class>
    <relationship-partner-attribute-name>ffclientCollection</relationship-partner-attribute-name>
    <is-private-owned>false</is-private-owned>
    <uses-batch-reading>false</uses-batch-reading>
    <indirection-policy>
    <mapping-indirection-policy>
    <type>oracle.toplink.internal.indirection.BasicIndirectionPolicy</type>
    </mapping-indirection-policy>
    </indirection-policy>
    <uses-joining>false</uses-joining>
    <foreign-key-fields>
    <field>LSB.FFCLIENT.CLIENT_ID</field>
    <field>LSB.FFCLIENT.LOAN_ID</field>
    </foreign-key-fields>
    <source-to-target-key-field-associations>
    <association>
    <association-key>LSB.FFCLIENT.LOAN_ID</association-key>
    <association-value>LSB.CLIENT_LOAN.LOAN_ID</association-value>
    </association>
    <association>
    <association-key>LSB.FFCLIENT.CLIENT_ID</association-key>
    <association-value>LSB.CLIENT_LOAN.CLIENT_ID</association-value>
    </association>
    </source-to-target-key-field-associations>
    <type>oracle.toplink.mappings.OneToOneMapping</type>
    </database-mapping>

    Yes, many thanks for you reply.
    My project has many layer (include DAO + EJB + BO + WEB).
    Toplink objects which are auto created by TopLink has only using in DAO and EJB layer, then toplink objects are transfer to Bean objects (valueObject) which are contain primitive java type as int, long, double... not java wrapper object as Integer, Long, Double... Bean objects are using from EJB to WEB layer. So when set value to bean object from toplink object I sometime don't set all reference toplink object to reference object of bean (although bean has references bean object as toplink object) because there are too big. So when I update data from WEB layer to EJB layer, before update to database, I must get fill all data for foreign key of update object by create new reference toplink object, add reference_id to this object and set it to update object. I waste a lot of time, its very handwork and tire. Are you has any solution about this problem?
    Thank in advanced.
    ThangNQ

  • Creation of Index for Primary & Foreign Key required?

    hi,
    i would like to find out if a column is defined as the primary key, do i need to create a separate index for it? or defining a primary key will tell the db to automatically create an index for it?
    does foreign key have the same behavior as the primary key constraint?
    thanks!

    i would like to find out if a column is defined as the primary key, do i need to create a separate index for it? No
    or defining a primary key will tell the db to automatically create an index for it? Yes
    See
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg05itg.htm#7265
    does foreign key have the same behavior as the primary key constraint?No. See http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg05itg.htm#1574

  • Need help on how to code this SQL statement! (one key has leading zeros)

    Good day, everyone!
    First of all, I apologize if this isn't the best forum.  I thought of putting it in the SAP Oracle database forum, but the messages there seemed to be geared outside of ABAP SELECTs and programming.  Here's my question:
    I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    Unfortunately, I don't have a lot of experience coding SQL, so I'm not sure how to resolve this.
    Please help!  As always, I will award points to ALL helpful responses!
    Thanks!!
    Dave

    >
    Dave Packard wrote:
    > Good day, everyone!
    > I would like to join the tables FMIFIIT and AUFK.  The INNER JOIN will be done between FMIFIIT's MEASURE (Funded Program) field, which is char(24), and AUFK's AUFNR (Order Number) field, which is char(12).
    >
    > The problem I'm having is this:  All of the values in AUFNR are preceeded by two zeros.  For example, if I have a MEASURE value of '5200000017', the corresponding value in AUFNR is '005200000017'.  Because I have my SQL statement coded to just match the two fields, I obviously get no records returned because, I assume, of those leading zeros.
    > Dave
    You can't do a join like this in SAP's open SQL.  You could do it in real SQL ie EXEC.... ENDEXEC by using SUSBTR to strip off the leading zeros from AUFNR but this would not be a good idea because a)  modifying a column in the WHERE clause will stop any index on that column being used and b) using real SQL rather than open SQL is really not something that should be encouraged for database portability reasons etc. 
    Forget about a database join and do it in two stages; get your AUFK data into an itab, strip off the leading zeros, and then use FAE to get the FMIFIIT data (or do it the other way round). 
    I do hope you've got an index on your FMIFIIT MEASURE field (we don't have one here); otherwise your SELECT could be slow if the table holds a lot of data.

  • No join predicate for this foreign key -error while importing the EUL

    Hello
    Anyone getting this error?I am trying to import 11i business areas into R12 EUL and I am getting this
    appreciate any feedback
    thanks
    kp

    Also check metalink note 1082644.1, this problem can be caused when importing into an Apps mode EUL using the EUL owner database account, rather than an eBusiness Suite user account.
    We've just had this exact problem, which was caused by something slightly different - an id column that was used in a join had been deleted. Discoverer does not cascade the delete, so the join was still in place, but with a blank formula. Disco reported no errors until an attempt was made to migrate this EUL from one environment to another. Deleting the join fixed the problem.
    HTH
    Matt

  • Binding for table produces list for other tables using foreign key and crea

    Using
    software Jdev 11G, WLS 11G, Oracle DB 11G, Windows Vista platform
    technology EJB 3.0, jspx, backing beans, session bean
    I cannot create a namedquery on my secondary table. The method for the column uses the entity object rather than the name and value of the column.
    For instance,
    (Coketruck) table has inventory records(Products) table
    Coketruck has one to many to the Products table
    Products has a many to one to the Coketruck
    I need to return the products from the product table based on the CokeTruck but I cannot create a namedQuery because the method in the Product table is an entity object type instead of a long that I can use to look up all the products based off the column truck_id.
    This is what I was expecting…
    Private Long truckId;
    public Long getTruckId() {
    return truckId;
    public void setTruckId (Long truckId) {
    this. truckId = truckId;
    Instead this is what I have…
    @ManyToOne
    @JoinColumn(name = "TRUCK_ID")
    private Coketruck coketruck;
    this. coketruck = coketruck
    public Coketruck getCoketruck() {
    return coketruck;
    public void set Coketruck (Coketruck coketruck) {
    this. coketruck = coketruck;
    How do I do a query on the Product table to return all the products that are in the coketruck?
    If I do the following it expects for me to pass the Entity Object which I cannot use as search criteria for my find method.
    @NamedQuery(name = "Products.findById", query = "select o from Products o where o.truckId = :truckId")
    On a different note but the same song…
    I noticed that when I look at my Session Bean Data Contols that the coketruck already has a list of the products. I have created a jsp page with a backing bean and have been able to use the namedquery on the coketruck entity to retrieve the productList. Unfortunately I need to sort the products by type and was also not able to find where to perform the work to be able to iterate through the productList to get my desired display. Therefore I started looking at doing another namedquery that would only retrieve the product_type ordering by the truckId.
    Seems I have come full circle… I don’t care what method I have to use to get the info back.
    Any help is greatly appreciated!

    user9005175 wrote:
    Hi!
    I work on an application wich uses a shopping cart stored in a database. The shopping cart uses two tables:
    CART: Holds information common for one shopping cart: the user it is connected to etc.
    - Primary key: CART_ID
    CART_ROW: One row in the cart, e.g. one new product to buy.
    - Primary key: ROW_ID
    - Foreign key: CART_ROW.CART_ID references CART.CART_ID
    From the code the rows in the cart are collected per cart, as is modelled by the foreign key. There exists one more relationship, which we use in the code, but which is not modelled by a foreign key in the database. One row can be dependent on another row, which makes the other row a parent.
    CART_ROW has a column PARENT_ID which references CART_ROW.ROW_ID.
    Should we add a foreign key for PARENT_ID? Or are there any questions to consider when it is a foreign key to the same table?
    I suggest to add foreign key it wont harm the performance (except while on insert when there would be validation for the foreign key). But it would prevent users to insert wrong/corrupt data either through code or directly by loggin in the database.
    A while ago we added indexes, both on ROW_ID and on PARENT_ID. Could the index on PARENT_ID have been harmful, since there is no foreign key?
    Index on parent_id would only be harmful if you do not make use of index after creating it (i.e. there is no query which make use of this index).
    And if you decide to have a foreign key on parent_id then I suggest to have index too on parent_id as it would be helpful atleast when you delete any record in this table.
    Best regards!

  • How can I create a new entry without using LOV for foreign keys.

    Referring to TUHRA sample application based on HR database schema. JDeveloper 10.1.3.0.4
    How can I create a new employee without using LOV for the foreign key "job_id".
    On the first page I would like to choose the job_title from adf read-only table.
    After clicking on the "create new employee button" a creation form appears in which the job_id field is set with previous selection.
    Regards M.Winkler
    Edited by: user3541283 on 06.10.2008 03:44
    Edited by: user3541283 on 06.10.2008 03:50

    Hi,
    usually the foreign key is only set if the VO you select is dependent from a master. If e.g. you have DepartmentsVO1 that has an EmployeeVO3 as its nested VO, then creating a new instance of employees automatically add the foreign key. If you add EmployeesVO1, which is not dependent to DepartmensVO1, then the foreign key is not set. So if this is the case in THURA (keep in mind that this is not an Oracle demo but a sample used in a book about ADF) then all you need is to take the independent VO when building the new employee form.
    Frank

  • SQL Developer Data Modeler - Relation to Foreign Key Generation

    SQL Developer Data Modeler 2.0.0 Build 584.
    I am having trouble with Relations to Foreign Keys when Forward Engineering a Relational Model from a Logical Model.
    First of all, the Naming Standard is not applied to the Foreign Keys when I perform the Engineer to Relational Model.
    So I right click on the Relational Model from the Browser and Apply Naming Standards to Keys and Constraints.
    I uncheck everything but Foreign Keys.
    Now, Foreign Keys are named according to my Naming Standards.
    However, this process also performs renames on the Column Foreign Keys even though I specifically unchecked that option.
    This appears to be a BUG in the software and I haven't found a way around it.
    I tried using {column} instead of {ref column} in the Naming Standard Template for Column Foreign Key, but that simply resulted in renaming my columns to "{column}".
    Please confirm and/or let me know of any work-around for this.
    Thanks,
    Dan

    Hi Philip,
    Thanks for the reply.
    Is this recorded as a bug to be addressed in the future?
    Should I submit this problem via Oracle Support?
    The other work-around I came up with is to override every Relation name in the Logical Model with the name I want to use in the Relational Model.
    When the Relational Model is Engineered, this becomes my Foreign Key name.
    Of course, this is not how I want to do things, so I am hoping for a bug fix someday.
    Regards,
    Dan

  • Foreign Keys for a Logical Table

    Hi All,
    I want to know in which scenarios we create the Foreign Keys for a Logical Table. Once we create the foreign key for the logical table, does it mean that it will automatically override if any joins are there.
    Physical Table A, B ( no physical joins)
    Logical Table A, B (logical join B(Dim)-->A(Fact))
    created the foreign key in logical table A with B .(A.1=B.1)
    Will the rpd generate sql with A.1=B.1 join condition for reports.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    http://tinypic.com/r/jq1gkz/6
    Thanks,
    Virat

    In general when we go complex joins in Physical layer we go for Logical foreign key joins in BMM layer, best examples is SCD Type-II.
    Physical Table A, B ( no physical joins)
    -->You need to have a physical join so that this can be override by BMM layer
    created the foreign key in logical table A with B .(A.1=B.1) Will the rpd generate sql with A.1=B.1 join condition for reports.
    -->Yes you can see this join in BI Physical query.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    -->2 cases: 1)You need to delete existing logical joins 2) You might not have join in physical layer.
    Hope this helps
    Let me know for issues
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM
    BTW: You got very good name, why dont you update in your profile to see your name instead of some number
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM

  • Maintenance View for custom table with foreign key relationship

    Hi Folks,
         I have created a custom table with foreign key relationship with other check tables. I want to create a maintenance view / tablemaintenance generator. What all things I need to take care for the foreign keys related fields while creating the maintenance view / tablemaintenance generator.
    Regards,
      santosh

    Hi,
    You do not have to do anything explicitely for the foreign key relationships in the table maintainance generator.
    Create the table maintainance generator via SE11 and it will take care of all teh foreign key checks by itself.
    Regards,
    Ankur Parab

  • Storage for Foreign Keys and Function based indexes

    This may well be the silliest question of the day, but is it possible to specify the storage for a Foreign key or a function based index? I'm not even sure that it would make sense.

    Well, a foreign key constraint is not a segment, nor is any other type of constraint. However, a function-based index is a segment, just like any other index. So, in that case, specify a tablespace, just like you would with any other index.
    Something like this:
    create index my_fbi on my_tab(upper(last_name)) tablespace my_index_tablespace;
    -Mark
    Message was edited by:
    mbobak
    Fixed minor typo.

  • How to declare Compound Foreign Key for CMR

    Hi All,
    I would like to know, is it possible to declare CMR field for Compound Foreign key.
    Any Pointers would be appreicated.
    Thanks
    Ann.

    Compound foreign keys are declared (when the relationships are used) in the sun-cmp-mappings.xml file, like this:
          <cmr-field-mapping>
            <cmr-field-name>actividadePeriodos</cmr-field-name>
            <column-pair>
              <column-name>ACTIVIDADE.COD_PROJECTO</column-name>
              <column-name>ACTIVIDADE_PERIODO.COD_PROJECTO</column-name>
            </column-pair>
            <column-pair>
              <column-name>ACTIVIDADE.COD_ACTIVIDADE</column-name>
              <column-name>ACTIVIDADE_PERIODO.COD_ACTIVIDADE</column-name>
            </column-pair>
            <fetched-with>
              <none/>
            </fetched-with>
          </cmr-field-mapping>The declaration is done in the parent of the relationship. The other configurations (in sun-cmp-mappings, ejb-jar and the entity code) are just the same as for simple foreign keys.
    If the existing database relationships are not used in the app server (if there is no need for composite containment between the parent and the child), then the foreign keys don't need to be declared.

  • Logical foreign key

    Hi All,
    I apologize to bring similar question. .
    I am able to create the logical foreign key for logical table A with new joining condition (A.2=B.2) (2 is calculated logical column).
    However there still exist Physical foreign key join with old condition (A1.=B.1). When I deploy this rpd, the report generates sql with (A1.=B.1) join condition.
    Then,I removed this Physical foreign key join in rpd,and got a warning' logical dimension B has a source that does not join with any fact table' in consistency check.
    Still after deploying this rpd , I am getting error [nQSError: 14025] No fact table exists at the requested level of detail: in report.
    I am missing anything.The logical foreign key has correct join condition still it is not over riding the physical join.
    Thanks for going through this question,
    http://tinypic.com/r/2qiwmrr/6

    Based on your comments I'm looking at documentation:
    I found a Note: A logical key for a fact table must be made up of the key columns that join to the attribute tables. Logical foreign key joins may be needed if the Oracle BI Server is to be used as an ODBC data source for certain third-party query and reporting tools.
    I need to see why ODBC, and unlike the Logical Foreign key join is not overriding join Physical layer.
    Btw: Since you want to go with a join using defined logical column, can you use the same expression in Physical join using expression builder?
    This should work.
    EX: T43770.DEPARTMENT_ID = case when T43764.DEPARTMENT_ID > 10 then T43764.DEPARTMENT_ID else 0 end
    Edited by: Srini VEERAVALLI on Jan 18, 2013 4:52 PM

Maybe you are looking for

  • Adding alt text tags in InDesign (and Acrobat Pro)

    I am having real difficulty adding alternative text tags. I created an INDD doc with rollover buttons linked to URLs firstly in InDesign CS4. I couldn't add alt text tags in CS4 so I then tried to add them in Acrobat X Pro but failed. Acrobat keeps w

  • How do I install a purchased adobe acrobat pro XL cd to my windows 7 desktop?

    How do I install a purchased adobe acrobat pro XL cd to my windows 7 desktop?

  • Subversion: Cannot import files into a local repository

    If following the directions from here: http://www.oracle.com/technology/products/jdev/htdocs/partners/addins/exchange/subversion/subversion.html I've got the local repository created and can successfully connect to it, but when it try to import files

  • Can not import photos from my Nikon D810

    I recently bought the new Nikon D810. I just spent all weekend with it and got some fantastic images. So naturally I came home and immediately went to import them. I'm also using Lightroom 4. and I had no image previews, so I thought to myself perhap

  • Best location for application files

    In our current WebLogic environment (WLS 4.51), we have seperate document roots for each of te 12 seperate applications being served up in seperate WebLogic instances. We are migrating to WLS6.1, and I am not sure if I should continue this practice.