Jump to content

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 . ";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.