Results 1 to 9 of 9

Thread: SQL question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Posts
    147

    Question SQL question

    I have ACCESS 2000 in two different computers and copy the same db to these, and then copy the same SQL(Select)-question and get different answers, what can be the reason

  2. #2
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Why dont you post your database & the SQL statement here...
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  3. #3
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Eh? that shouldnt happen...
    Leather Face is comin...


    MCSD

  4. #4
    Frenzied Member mxnmx's Avatar
    Join Date
    Dec 2001
    Location
    I'm back...now!!!
    Posts
    1,396
    Yea, that shouldnt happen, it might just be some small problem...somewhere....
    Can't Remember Birthdays or Important Dates- Never Miss any Important Date(s)

  5. #5

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Posts
    147

    Question Well

    I think that I know where the problem is

    Say that I am joining two tables (The SQL question is mutch bigger than this in reality)

    Select Table1.Field1, Table2.Field2
    FROM Table1 LEFT JOIN Table2 ON Table1.Field1 = Table2.Field1
    WHERE ...

    Now Field2 is not always existing in Table2, but I still want the value of Field1 in Table1, So I choose to use a LEFT JOIN

    Now I want to have a selection on which field2:s in Table2 I want to join with.

    I can't have it after WHERE Like:
    "WHERE Table2.Field3 = 1" when it would conflict with which fields of Table1.Field1 that would be Selected so i tried something like

    FROM Table1 LEFT JOIN Table2 ON Table1.Field1 = Table2.Field1 AND Table2.Field3 = 1
    WHERE

    Access accepts it...
    but it seems like the question get ambiguous then...
    (At least I can see that it happens...)

    Maybee I'm overlooking something easy, when the question is quite complex with 2 other questions inside itself (One as a selected field and one as a selection) and 2 left joins but how do I restrict the the joined fields whitout affecting the hole question in the question above?

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Use Left outer join:

    Code:
    SELECT tblJobs.JobNumber, ISNULL(tblInvoices.InvoiceNumber, '') AS invoiceNumber
    FROM tblJobs
    LEFT OUTER JOIN tblInvoices ON tblInvoices.JobNumber = tblJobs.JobNumber AND tblInvoices.Cancelled = FALSE
    WHERE tblJobs.Cancelled = FALSE
    Woka

    PS It still won't affect your original Q. (Post number 1)

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Posts
    147

    Cool Ok

    I will try that as soon as I can get my hand on the computer where the question don't work. On my computer the OUTER don't affect a thing, I still get the right answer with or without it. Hopfully I get the same right answer on the other computer if I use it, otherwise I'll be back...

    Hmm... do you think that MDI-forms isn't good for anything?

  9. #9

Posting Permissions

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



Click Here to Expand Forum to Full Width