Jump to content

Union Won't Merge SQL


unemployment

Recommended Posts

" ON `vote_sent`.`uid` = `users`.`id`"

 

doesn't make any sense to me.  Why is there no user id in the vote table?

 

user id in the votes table is only added if the user is logged in.  If the user is not logged in then it is a public vote and no user id is recorded.  Does that make sense?

Link to comment
Share on other sites

This is what I have so far... but I'm confused about ref_id vs user_id in the beta_keys table.

 

	SELECT
				CHAR_LENGTH(`users`.`credentials`) AS `cred_chars`,
				CHAR_LENGTH(`users`.`specialties`) AS `spec_chars`,
				`companies`.`companyvideo` AS `video`,
				`investor_info`.`accredited` AS `accredited`,
          ( SELECT COUNT(`user_id`) FROM `blog_posts` WHERE `user_id` = '1' ) AS `post_count`,
          ( SELECT COUNT(`uid`) FROM `votes` WHERE `uid` = '1' ) AS `vote_sent_count`,
				`votes_received`.`inv_vote_received_count`,
				`votes_received`.`pub_vote_received_count`,
          ( SELECT COUNT(`userid`) FROM `employees` WHERE `userid` = '1' ) AS `joined_count`,
				`votes2`.`ent_count`,
				`votes2`.`inv_count`,
			 (
					SELECT
						COUNT(`company_id`)
					FROM `company_fans`
					LEFT JOIN `companies` ON `company_fans`.`company_id` = `companies`.`companyid`
					LEFT JOIN `employees` ON `employees`.`companyid` = `companies`.`companyid`
					WHERE `userid` = '1'
			) AS
				`company_fans_count`,
          ( SELECT COUNT(`user_id`) FROM `recommendations` WHERE `user_id` = '1' ) AS `recommendation_count`,
          ( SELECT COUNT(`partner_id`) FROM `partners` WHERE (`user_id` = '1' OR `friend_id` = '1') AND `approved` = '1' ) AS `associate_count`
			 FROM `users`
         LEFT JOIN `investor_info` ON `investor_info`.`uid` = `users`.`id`
			 LEFT JOIN `employees` ON `employees`.`userid` = `users`.`id`
			 LEFT JOIN `companies` ON `employees`.`companyid` = `companies`.`companyid`
			 LEFT JOIN (
					SELECT
						`employees`.`userid`,
              				SUM( IF( `votes`.`vote_type` = 1, 1, 0 ) ) AS `inv_vote_received_count`,
              				SUM( IF( `votes`.`vote_type` = 0, 1, 0 ) ) AS `pub_vote_received_count`
					FROM `votes`
					INNER JOIN `employees` ON `employees`.`companyid` = `votes`.`company_id`
					WHERE `employees`.`userid` = '1'
            				GROUP BY `employees`.`userid`
        					) AS `votes_received` ON `votes_received`.`userid` = `users`.`id`

			 LEFT JOIN (
					SELECT
						`beta_keys`.`ref_id`,
              				SUM( IF( `users`.`accounttype` = 1, 1, 0 ) ) AS `ent_count`,
              				SUM( IF( `users`.`accounttype` = 0, 1, 0 ) ) AS `inv_count`
					FROM `beta_keys`
					INNER JOIN `users` ON `users`.`id` = `beta_keys`.`userid`
					WHERE `beta_keys`.`ref_id` = '1' AND `users`.`status` = 3
            				GROUP BY `users`.`id`
        					) AS `votes2` ON `votes2`.`ref_id` = `users`.`id`


			 WHERE `users`.`id` = '1'
;

Link to comment
Share on other sites

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.