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 > return records with zero count

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-08, 04:49
homer.favenir homer.favenir is offline
Registered User
 
Join Date: Oct 2007
Location: Manila, Philippines
Posts: 132
Talking return records with zero count

hi,
i have a query but it displays only those records with count, and those with no count doesnt display

here is my query

SELECT
tbl_menu.menu_date,
tbl_menu.concessionaire,
tbl_menu.picture,
tbl_menu.meal,
tbl_menu.`type`,
tbl_menu.price,
(tbl_menu.availability - count(tbl_order.`order`)) as 'Available'
FROM
tbl_menu
inner join tbl_order on (tbl_menu.meal = tbl_order.`order`)
Group by
tbl_order.`order`

i have a count(tbl_order.`order`) = 0 but it does not appear.
this query only displays the records when count is not null
what i need is all records should disply even if the count is not null or null.

pls advice.
thanks
__________________
Take Nothing But Pictures;
Leave Nothing But Footprints;
Kill Nothing But Time;
Reply With Quote
  #2 (permalink)  
Old 03-24-08, 08:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
SELECT tbl_menu.menu_date
     , tbl_menu.concessionaire
     , tbl_menu.picture
     , tbl_menu.meal
     , tbl_menu.`type`
     , tbl_menu.price
     , tbl_menu.availability - COALESCE(daCount,0) as Available
  FROM tbl_menu
LEFT OUTER
  JOIN ( SELECT `order`
              , count(*) AS daCount
           FROM tbl_order 
         GROUP
             BY `order` ) AS orders
    ON orders.`order` = tbl_menu.meal
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-24-08, 09:25
koriba koriba is offline
Registered User
 
Join Date: Mar 2008
Location: Windhoek Namibia
Posts: 13
in your query you could also subst .<<count(tbl_order.`order`)>> with <<(count(tbl_order.`order`)+1)>> and then know that in your other code. Nasty but works
__________________
Wayne Philip - openaxon.com
Reply With Quote
  #4 (permalink)  
Old 03-24-08, 23:22
homer.favenir homer.favenir is offline
Registered User
 
Join Date: Oct 2007
Location: Manila, Philippines
Posts: 132
thanks guys....
__________________
Take Nothing But Pictures;
Leave Nothing But Footprints;
Kill Nothing But Time;
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