Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MYSQL query doesn't work if row doesn't exist in a table
  2. SELECT albums.*, MAX(albums.date) AS newDate
  3. FROM albums, albumData
  4. WHERE albums.userID='$id'
  5. AND albums.state='0'
  6. AND (
  7.  albums.albumID=0
  8.  OR
  9.  albumData.id=albums.albumID
  10.  AND albumData.state='0'
  11. )
  12. GROUP BY albums.albumID, albums.userID
  13. ORDER BY newDate DESC
  14.        
  15. SELECT albums.*, MAX(albums.date) AS newDate
  16. FROM albums WHERE userID=$id AND albums.state='0'
  17. GROUP BY albums.albumID ORDER BY newDate DESC
  18.        
  19. if($quer['id']&&$quer['state']==0||$albumID==0)
  20. {//do my stuff here }
  21.        
  22. SELECT  albums.*
  23.         , MAX(albums.date) AS newDate  
  24. FROM    albums
  25.         LEFT JOIN albumData ON albumData.id = albums.albumID
  26. WHERE   albums.userID='$id'  
  27.         AND albums.state='0'  
  28.         AND (albums.albumID=0  OR albumData.state='0')  
  29. GROUP BY
  30.         albums.albumID
  31.         , albums.userID
  32. ORDER BY
  33.         newDate DESC