Solved

SQL query help

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Syntax 5 39
Access Crosstab Query with Multiple Values 4 49
string fuctions 4 28
SQL Stored Proc - Performance Enhancement 15 55
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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