home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / database / oracle / 1419 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  3.4 KB

  1. Path: sparky!uunet!gatech!hubcap!ncrcae!ncrlnk!ncrsoph!sstasuke
  2. From: sstasuke@ncrsoph.Sophia.NCR.COM (Steve Stasukewicz)
  3. Newsgroups: comp.databases.oracle
  4. Subject: How to do this in SQL ?
  5. Message-ID: <4067@ncrsoph.Sophia.NCR.COM>
  6. Date: 28 Aug 92 15:09:40 GMT
  7. Reply-To: sstasuke@ncrsoph.Sophia.NCR.COM (Steve Stasukewicz)
  8. Distribution: world
  9. Organization: NCR European Development Center
  10. Lines: 73
  11.  
  12.  
  13. I'm new to SQL, ( and Oracle for that matter) so I'm relying on a little 
  14. help from the net. ( Actually, there's probably a very easy solution to 
  15. this. )
  16.  
  17. I have the following four tables.  Column names are the same to show
  18. relationships.  In the 'likes' table, a unique row is identified by a
  19. combination of all 3 columns.  In the 'item_type' table, a unique row
  20. is identified by a combination of f1 and f2.  In the other two tables,
  21. each field is unique to it's column.
  22.  
  23.  
  24.  
  25.        likes               item            item_type             employee
  26.  
  27.  emp_no   f1   f2       f1   txt1        f1   f2  txt2        emp_no   name
  28.  ------  ---- ----     ---- ------      ---- ---- ----        ------  -----
  29.   999     10   01       10  apples       10   01  green        999     john
  30.   999     10   02       20  bananas      10   02  red          123     sue
  31.   123     30   02       30  beer         20   01  yellow       848     lisa
  32.   848     20   10                        20   02  brown
  33.                                          30   01  bud
  34.                                          30   02  miller
  35.  
  36.  
  37.  
  38. From the  rows in table 'likes', I should be able to determine that john
  39. likes green and red apples, sue likes miller beer, and lisa likes
  40. yellow bananas. (Of course I don't know how to do this yet, but I should
  41. be able to figure this one out).  My other question is this:
  42.  
  43. 1) How can I select all employees who like green apples, but do NOT like
  44.    miller beer. ( In this case john.) You can tell someone does not like 
  45.    something by it's absence in the 'likes' table.  To take this a step
  46.    further, I would like to select all employees who like green apples,
  47.    miller beer, yellow bananas, and dislikes bud beer and red apples.
  48.  
  49.  
  50. Are these tables structured correctly for what I want?  I was also 
  51. thinking of combining the 'item' and 'item_type' tables into 1 table,
  52. and having 1 less column in the 'likes' table.  For SQL, is one approach
  53. more efficient than the other? 
  54.  
  55.  
  56.        new_item                                    likes
  57.  
  58.    c1    c2        c3                          emp_no   c1 
  59.   ---   ----     ------                        ------  ----
  60.    10   green    apples                          999    10
  61.    11   red      apples                          999    11
  62.    21   yellow   bananas                         848    21
  63.    22   brown    bananas
  64.  
  65.  
  66.  
  67. Of course with this structure, the replicated data is a variable length
  68. character field instead of a 2 or 3 digit number.   
  69.  
  70. Any comments, advice, solutions would be appreciated.  
  71.  
  72. Ciao
  73.  
  74. --------------------------------------------------------------------------------
  75. Steve.Stasukewicz@sophia.NCR.FR        GO HAWKS !  GO HAWKS !  GO HAWKS !
  76. NCR Europe Group ISS/ECS
  77. Espaces De Sophia
  78. 25 Route de Lucioles                   Tel. (33) 92.94.45.12
  79. 06560 Valbonne FRANCE                  Fax. (33) 92.94.45.45
  80.  
  81. "Operator, I'd like to make a long distance call to Iowa".
  82. "I'm sorry sir, all lines are busy.  Would you like to hold"?
  83. "WOULD I LIKE TO HOLD?!!  WOULD I LIKE TO HOLD ??!!!!  Yea, I'll hold".
  84. -- 
  85.