Jump to content

Need help understanding SQL Query.


atrum

Recommended Posts

Hello everyone,

 

I am working on a project that uses an sql query that is a little more advanced than what I have been exposed to in the past.

some

 

I understand most of it but it has some parts I don't really grasp.

Could any one break this down for me into parts and explain what it is this is doing?

SELECT c.* , (SELECT COUNT( * ) FROM `referrals` AS r WHERE r.`referrals_contact_id` = c.`contacts_id` ) AS gl_count FROM `contacts` AS c WHERE c.`contacts_demo_date` >= '" . $fromDateDB . "' AND c.`contacts_demo_date` <= '" . $toDateDB . "' AND `" . $_REQUEST['queryColumn'] . "` = " . $answer . ";

Link to comment
https://forums.phpfreaks.com/topic/238438-need-help-understanding-sql-query/
Share on other sites

SELECT c.* , // Select all columns from contacts

 

// Count number of values in referrals

(SELECT COUNT( * ) FROM `referrals` AS r WHERE r.`referrals_contact_id` = c.`contacts_id` ) AS gl_count

 

// refer to table "contacts" as c

FROM `contacts` AS c

 

// Conditions for results for c.

WHERE c.`contacts_demo_date` >= '" . $fromDateDB . "' AND c.`contacts_demo_date` <= '" . $toDateDB . "' AND `" . $_REQUEST['queryColumn'] . "` = " . $answer . ";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.