SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need to add WHERE uid=1

    I'd like to modify this to SELECT rows only from the user with ID of 1
    Code php:
    SELECT title_or_name, movie_or_show, title_slug, show_name, show_name_slug, season, episode, sort_album_artist, sort_album_artist_slug 
    	FROM (
    		SELECT 
    			title AS title_or_name, 
    			kind AS movie_or_show, 
    			title_slug, 
    			show_name,
    			show_name_slug,
    			season,
    			episode,
    			sort_album_artist,
    			sort_album_artist_slug
    		FROM movies WHERE kind='Movie' OR kind='Music Video'  
    		// this didn't work
    		AND uid=1
     
    		GROUP BY title 
    		UNION ALL
    		SELECT 
    			title, 
    			kind,
    			title_slug,
    			show_name,
    			show_name_slug, 
    			season,
    			episode ,
    			sort_album_artist,
    			sort_album_artist_slug
    		FROM movies WHERE kind='TV Show' 
    		// this didn't work
    		AND uid=1
    		GROUP BY show_name
    	) 
    	AS t 
    ORDER BY title_or_name, movie_or_show

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,270
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    gee, that looks eerily familiar...



    ANDs take precedence over ORs

    you have

    ... WHERE kind='Movie' OR kind='Music Video' AND uid=1

    this is equivalent to

    ... WHERE kind='Movie' OR ( kind='Music Video' AND uid=1 )

    what you want requires explicit parentheses

    ... WHERE ( kind='Movie' OR kind='Music Video' ) AND uid=1

    alternatively,

    ... WHERE kind IN ( 'Movie' , 'Music Video' ) AND uid=1
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard tgavin's Avatar
    Join Date
    Feb 2003
    Location
    FL
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    gee, that looks eerily familiar...

    It's a beautiful thing, isn't it?

    Thanks Rudy, that took care of it. And I got a good learnin' outta it too!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •