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 > SQL running slow

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-06-11, 23:08
EmSiden EmSiden is offline
Registered User
 
Join Date: Dec 2011
Posts: 1
SQL running slow

Dear all,

I am sorry if this topic is wrong because I am new in this forum.
Could you help me with the SQL process. I am using MySQL and connect with Joomla. I want to count all active and inactive job in my database but amount of record too much, So it process too slow. Do you have any trick to solve?

Thank in advance, your answer will appropriate..!!!

My code:


Code:
SELECT d.`id`, d.`name`, d.`email` AS `contact_email`, d.`notify`, d.`notify_admin`, d.`logo`, d.`status`
			,(SELECT COUNT(j.`id`) FROM `jos_jobboard_jobs` AS j WHERE j.`department` = d.`id` AND j.`published` = 1) AS active
			,(SELECT COUNT(j.`id`) FROM `jos_jobboard_jobs` AS j WHERE j.`department` = d.`id` AND j.`published` = 0) AS inactive
		    FROM `jos_jobboard_departments` AS d;
Reply With Quote
  #2 (permalink)  
Old 12-07-11, 02:45
it-iss.com it-iss.com is offline
Registered User
 
Join Date: Sep 2009
Location: San Sebastian, Spain
Posts: 620
Try something like this:

Code:
SELECT d.`id`, d.`name`, d.`email` AS `contact_email`, d.`notify`, d.`notify_admin`, d.`logo`, d.`status`, SUM(IF(j.published=1,1,0)) active, SUM(IF(j.published=0,1,0)) inactive
FROM `jos_jobboard_departments` AS d
LEFT JOIN jos_jobboard_jobs AS j ON j.department = d.id
GROUP BY d.`id`, d.`name`, d.`email` AS `contact_email`, d.`notify`, d.`notify_admin`, d.`logo`, d.`status`;
__________________
Ronan Cashell
Senior Oracle/MySQL DBA
http://www.it-iss.com
Reply With Quote
Reply

Tags
mysql

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