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 > Help with isNULL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-27-08, 07:12
suami suami is offline
Registered User
 
Join Date: Oct 2008
Posts: 6
Help with isNULL

hello,
Does someone know why i'm getting this error:


**** the select for t1****
)t1
LEFT JOIN (

SELECT ROUND(ISNULL(sum(p_sum),0),3) AS Total, fk_id AS id
FROM abc
GROUP BY id
)t2 ON t1.id = t2.id


and i'm getting this error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0),3) as Total, fk_id as id
from abc
group b' at line 17

thanks!
Reply With Quote
  #2 (permalink)  
Old 10-27-08, 07:29
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
the ISNULL function takes only one parameter

use this instead --

... ROUND(COALESCE(SUM(p_sum),0),3)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 10-27-08, 07:34
suami suami is offline
Registered User
 
Join Date: Oct 2008
Posts: 6
first of all, thank you for the quick response..

I changed it, and Now I don't get an error but I still get NULL instead of zero in the Total column

thanks again..
suami.
Reply With Quote
  #4 (permalink)  
Old 10-27-08, 07:40
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Run the subquery on it's own - any NULLs?

I'm assuming the LEFT JOIN is what is introducing the NULL values.
__________________
George
Twitter | Blog
Reply With Quote
  #5 (permalink)  
Old 10-27-08, 07:43
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
because it's a LEFT OUTER JOIN

do the COALESCE in the outer query
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 10-27-08, 07:44
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
arg, sniped by george again
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 10-27-08, 07:46
suami suami is offline
Registered User
 
Join Date: Oct 2008
Posts: 6
Sorry but I didn't get you.. if you could please explain what you meant i'll be very thankful..
Reply With Quote
  #8 (permalink)  
Old 10-27-08, 07:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
if you could please post the actual query, i could help you
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 10-27-08, 07:58
suami suami is offline
Registered User
 
Join Date: Oct 2008
Posts: 6
select * from (SELECT id,
id_contact,
id_address,
name,
total_price,
full_com
FROM sale as s
INNER JOIN click as c ON s.click=c.click
INNER JOIN partner as p ON p._id = b.fk_id
WHERE sale_stat in(1,5)
Group by p.id) t1
LEFT JOIN (
select round(COALESCE(sum(advp_sum),0),3) as Total, fk_id as id
from abc
group by id
) t2 ON t1.id = t2.id


thanks.
Reply With Quote
  #10 (permalink)  
Old 10-27-08, 08:03
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Quote:
Originally Posted by suami
select * from (SELECT id,
id_contact,
id_address,
name,
Coalesce(total_price, 0),
full_com
FROM sale as s
...
Meh .
__________________
George
Twitter | Blog
Reply With Quote
  #11 (permalink)  
Old 10-27-08, 08:20
suami suami is offline
Registered User
 
Join Date: Oct 2008
Posts: 6
But total price is not in t2, and I would like to make the column of adv_sum which if it's null the i want zero instead, sorry for keep asking i guess don't explain my self right,
Reply With Quote
  #12 (permalink)  
Old 10-27-08, 08:23
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Apologies, mis-read your query.
Change your SELECT * to pick out specific columns. Then apply the Coalesce at that point
__________________
George
Twitter | Blog
Reply With Quote
  #13 (permalink)  
Old 10-27-08, 08:32
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by suami
select * from (SELECT id,
id_contact,
id_address,
name,
total_price,
full_com
FROM sale as s
INNER JOIN click as c ON s.click=c.click
INNER JOIN partner as p ON p._id = b.fk_id
WHERE sale_stat in(1,5)
Group by p.id) t1
LEFT JOIN (
select round(COALESCE(sum(advp_sum),0),3) as Total, fk_id as id
from abc
group by id
) t2 ON t1.id = t2.id

this cannot be your real query, because it references a table (b) which doesn't exist


like i said before, do the COALESCE in your outer query
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #14 (permalink)  
Old 10-27-08, 11:07
suami suami is offline
Registered User
 
Join Date: Oct 2008
Posts: 6
Thank you so much for the help!
got you. worked.
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