Does ID exsist in any table?

Results 1 to 2 of 2

Thread: Does ID exsist in any table?

  1. #1
    Join Date
    Dec 1969

    Default Does ID exsist in any table?

    I am trying to search 2 tables to get information about a record and to find out if this primary key exists as a foreign key in any of the two tables. The tables are set up like this:<BR><BR>Categories:<BR>Cat_ID<BR>Cat_Name <BR>Cat_Desc<BR>Cat_ParentID (Cat_ID) Categories can have sub-categories<BR><BR>Files: <BR>File_ID<BR>File_Name<BR>File_Desc<BR>File_Pare nt (Cat_ID) A file can only be associated with one parent category<BR><BR>I am using this query to see if a cat_ID is the parent of any other categories. <BR><BR><BR>*** How can I extend this to see if this category (cat_ID) is a parent of a file (file_Parent)? ***<BR><BR> SQL = _<BR> "SELECT T1.cat_ID as ID, T1.cat_name as name, Count(T1.cat_ParentID) AS theCount," & _<BR> " T1.cat_Desc, T1.cat_sortOrder AS sortorder, 0 AS cat_type, u.user_ID as user," & _<BR> " u.user_FName as fname, u.user_LName as lname, T1.cat_Date" & _<BR> " FROM file_categories AS T1, file_categories AS T2, users AS u" & _<BR> " WHERE T2.cat_ParentID=T1.cat_ID And T2.cat_User=u.user_ID" & _<BR> " AND T1.cat_ParentID = " & item_ID & _<BR> " AND T1.cat_threadID = " & thread_ID & _<BR> " GROUP BY T1.cat_ID, T1.cat_name, u.user_ID, u.user_FName, u.user_LName," & _<BR> " T1.cat_Desc, T1.cat_sortOrder, t1.cat_Date" <BR> &#039;" ORDER BY T1.cat_name;" <BR> <BR>

  2. #2
    Join Date
    Dec 1969

    Default UNION

    Select &#039;CAT&#039;, T1.Cat_ID, T1.Cat_Name <BR> FROM Categories AS T1, Categories AS T2<BR> WHERE T1.Cat_ID = T2.Cat_ParentID<BR>UNION<BR>Select &#039;CAT&#039;, T1.Cat_ID, T1.Cat_Name<BR> FROM Categories AS T1, Files AS T2<BR> WHERE T1.Cat_ID = T2.File_Parent<BR>ORDER BY T1.Cat_Name<BR><BR>You get to add the other stuff in for the other fields. But that&#039;s the basic idea.<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts