Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2002
    Location
    Nepal
    Posts
    32

    Unanswered: Please correct this Query

    Hi,

    I need something like below query, i tried it but did not work error comes with "Syntax error"

    select payments.id, payments.cid, payments.ctype, payments.date from payments

    if(payments.ctype = 2, join clientst1 ON payments.cid = clientst1.cid)
    elseif(payments.ctype = 3, join clientst3 ON payments.cid = clientst3.cid)
    elseif(payments.ctype = 4, join clientst4 ON payments.cid = clientst4.cid)
    Where
    if(payments.ctype = 2, clientst1.customer_id = 4)
    if(payments.ctype = 3, clientst3.customer_id = 4)
    if(payments.ctype = 4, clientst4.customer_id = 4)
    LIMIT 50;


    Best Regards,

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    why do you have three different client tables? can't you see how much unnecessary complexity this forces into your query?

    imagine what your SQL would be like if you had only one client table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2002
    Location
    Nepal
    Posts
    32
    The problem is, i am working other designed database, and if i will change the structure his Desktop application will not work.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by abdul_zu View Post
    The problem is, i am working other designed database, and if i will change the structure his Desktop application will not work.
    then you are in the stinky stuff pretty deep, eh

    hey, let me ask you a question

    your SELECT clause returns only columns from the payments table

    why are you bothering with the clients table anyway?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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