?
Solved

SQL query help

Posted on 2014-11-01
3
Medium Priority
?
73 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 1000 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 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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