Solved

SQL query help

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

13 Experts available now in Live!

Get 1:1 Help Now