If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Please correct this Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-03-10, 10:23
abdul_zu abdul_zu is offline
Registered User
 
Join Date: Dec 2002
Location: Nepal
Posts: 32
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,
Reply With Quote
  #2 (permalink)  
Old 01-03-10, 14:35
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-04-10, 03:37
abdul_zu abdul_zu is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 01-04-10, 07:07
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On