Solved

SQL query help

Posted on 2014-11-01
3
68 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

15 Experts available now in Live!

Get 1:1 Help Now