Left/righ join dont know anymore

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Left/righ join dont know anymore

    Hi all,

    I need to get all the records from one table but only if some values from
    other tables are verified. Ok, so this should be normal like:

    select * from
    tableA, tableB, tableC
    where tableB.hostid = 1
    and tableC.groupid <> 1

    This should actually give me all records from tableA if hostid from tableB is
    "1" and groupid from tableC is not "1".

    So actually this returns me nothing, because not all records from tableA are
    in tableC. So I thought to use a left join but all I have tried does not work
    at all.

    Any kind soul please enlighten me? Thank you.


    nitai_co Guest

  2. Similar Questions and Discussions

    1. Is left-join faster then inner join?
      Some people said that using left-join is generally faster than inner join, is that true? Thanks...
    2. left join limit 1
      I have 3 tables, one main table, and two tables that reference the first table. the two reference tables may have more than one entry to the first...
    3. Left join isn't joining
      Hello, I've got a select statement that joins two tables. -- tblPageHitCalendar contains a single column holding dates. It has every day since...
    4. swf files dont open in Flash Player Anymore!
      Now every time I try to open a .swf file it asks me what program do i want to open it in i have installed flash again and again and it still isant...
    5. left join problem
      if you just need something unique in the result set, 1. combination (NJIDATA.GLPMSTR.ID, NJIDATA.GLPMTRN.ID) is unique 2. you could also use...
  3. #2

    Default Re: Left/righ join dont know anymore

    Put the code you tried with outer joints. What database do you query?
    CF_Oracle Guest

  4. #3

    Default Re: Left/righ join dont know anymore

    Also, you aren't relating the three tables to one another. How is table A
    related to B and B to C (or A), etc.? I am surprised that you didn't get a
    Cartesian join, where you return a product of the numer of rows in each table,
    rather than nothing.

    Phil

    paross1 Guest

  5. #4

    Default Re: Left/righ join dont know anymore

    Paross you are right. That what I mean asking nitai_co to "put the code with
    outer joints" here for our review and possible help. But it could be
    interpreted as advise what to do. Since he/she wrote "I thought to use a left
    join but all I have tried does not work at all" these 3 tables heve been
    jointed somehow. Anyway we need to no foreign keys etc.


    CF_Oracle Guest

  6. #5

    Default Re: Left/righ join dont know anymore

    Ok, sorry if I did not write it out properly. But the code I wrote is actually
    what I am doing and I get ALL the record, but I need only the records from
    tableA who DONT have 1 in the tableC.groupid field.

    So this code:

    select * from
    tableA, tableB, tableC
    where tableB.hostid = 1
    and tableC.groupid <> 1

    shows me all records. Trying:

    select * from
    tableA, tableB, left join tableC on tablec.groupid <> 1
    where tableB.hostid = 1

    It was a long day and I dont know where to look anymore and what to do :-) (we
    are on Oracle 10g).

    PS: I am a he




    nitai_co Guest

  7. #6

    Default Re: Left/righ join dont know anymore

    That is what I meant by a Cartesian join (ALL records returned, actually all
    three tables times each other). What you need to add is how these tables are
    related. You only have where tableB.hostid = 1 and tableC.groupid <> 1, but how
    is tableB related to tableA? Something like tableA.hostid=tableB.hostid and
    also something like tableB.groupid = tableC.groupid, etc. (This is only an
    example, because you really didn't specify how these tables are related.)
    Otherwise, you just get the product of their rows times each other (a Cartesian
    join ).

    Phil


    paross1 Guest

  8. #7

    Default Re: Left/righ join dont know anymore

    Originally posted by: mxstu

    I'll let someone else post an optimization of that query ;-) ... but at the
    very least ... specify the column names instead of using "SELECT *".


    Yes, I always do, this was just for posting and making the code look "better"

    nitai_co Guest

  9. #8

    Default Re: Left/righ join dont know anymore

    Okay, that's what I thought. It never hurts to make sure. Amazing the amount of people that actually use select * on a regular basis...
    mxstu Guest

  10. #9

    Default Re: Left/righ join dont know anymore

    Really? hmhmhhm....those are the poeple who wonder why their application gets so slow when they hit a million records :-) Thank you for all suggestions.
    nitai_co Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139