Solved

SQL query help

Posted on 2014-11-01
3
66 Views
Last Modified: 2014-12-06
Hello, I'm creating a small app where admin users can judge videos. I'm getting good results from this current query but what I would ultimately like to do is now is to show all admin users that have judged or not with ADMIN_ROLE = 1. My query below only shows admins that have judged the videos only. I can't seem to figure that out.


SELECT *, t3.record_id AS recordID, SUM(onex + twox + threex) AS score
	FROM tag_playlists t1
	LEFT JOIN video_playlist_tag_rel t2
	ON t1.record_id = t2.video_playlist_tag_record_id
	INNER JOIN video_searches t3
	ON t2.video_rel_record_id = t3.record_id
	INNER JOIN video_status t4
	ON t3.record_id = t4.rel_record_id
	LEFT JOIN video_ratings t5
	ON t4.rel_record_id = t5.video_rel_record_id
	LEFT JOIN admins t6
	ON t5.user_id = t6.admin_id
	
	WHERE 0 = 0
	AND DATE(t3.search_request_date) = '#day#'

	GROUP BY t1.record_id, t3.record_id, t6.admin_id

Open in new window

0
Comment
Question by:brihol44
3 Comments
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
ID: 40417883
I'm quite unclear about this question I'm afraid.

"all admin users that have judged or not with ADMIN_ROLE = 1"

???
select * from admins where admin_role=1
???

My point is that you know what you want as output (we don't) and you know where every field comes from (we don't).

I suspect you need to turn your existing query upside down and use FROM ADMINS, then everything else joins through to that (mostly as LEFT JOINS) this will allow listing of all admins and you can identify those who have judged and those who have not.
0
 
LVL 12

Accepted Solution

by:
jkaios earned 250 total points
ID: 40418557
Seems to be a problem with your WHERE clause - it must reference a field as PortletPaul suggested.

This is wrong is the SQL query syntax:
   WHERE 0 = 0

Try changing it to:
  WHERE <tablename>.ADMIN_ROLE = 1

where <tablename> is the table where the field ADMIN_ROLE is located.
0
 

Author Closing Comment

by:brihol44
ID: 40485042
Thanks! Both of your solutions made me thing about it differently.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now