Click here to Skip to main content
15,903,362 members
Home / Discussions / Database
   

Database

 
GeneralRe: how to select a single row based on an aggregate SQL function result? Pin
scottgp25-Mar-10 3:22
professionalscottgp25-Mar-10 3:22 
GeneralRe: how to select a single row based on an aggregate SQL function result? Pin
michal.kreslik25-Mar-10 3:39
michal.kreslik25-Mar-10 3:39 
GeneralRe: how to select a single row based on an aggregate SQL function result? Pin
i.j.russell25-Mar-10 4:34
i.j.russell25-Mar-10 4:34 
GeneralRe: how to select a single row based on an aggregate SQL function result? Pin
scottgp25-Mar-10 6:44
professionalscottgp25-Mar-10 6:44 
GeneralRe: how to select a single row based on an aggregate SQL function result? Pin
michal.kreslik31-Mar-10 23:21
michal.kreslik31-Mar-10 23:21 
QuestionProblem with SQL Query Pin
stanley1825-Mar-10 1:46
stanley1825-Mar-10 1:46 
AnswerRe: Problem with SQL Query Pin
Mschauder25-Mar-10 2:55
Mschauder25-Mar-10 2:55 
AnswerRe: Problem with SQL Query Pin
Jörgen Andersson26-Mar-10 11:23
professionalJörgen Andersson26-Mar-10 11:23 
Try something similar to this:
select  p_id, 
        p_name, 
        p_path,
        case when uw.username is not null then uw.username 
             when um.username is not null then um.username 
             else null
        end creator,
        uw.username,
        um.username
from    pics
left join usersmobile um
    on  pics.p_userId_mobile = um.p_userId_mobile
left join  UsersWWW uw
    on  pics.p_userId_www = uw.p_userId_www

But your problem is really bigger than the query, your datamodel isn't very good.
You need to normalize the tables to avoid corruption of your data

Here's a suggestion (with room for improvement):
Image
  imageid PK
  name
  path

users /*only one usertable*/
  userid PK
  username

accesstype
  accesstypeid PK
  accesstype  /*www and mobile*/

useraccess
  useraccessid PK
  userid       FK
  accesstypeid FK

unique key (userid,accesstypeid)

imagecreated
  imagecreatedid PK
  imageid        FK
  useraccessid   FK
  createdate

unique key (imageid,useraccessid) /*an image can only be created once*/

imagechanged
  imagechangedid PK
  imageid        FK
  useraccessid   FK
  changedate


As this allows storage of several changes per image you need to rethink your original query, or use max(changedate) to get the last change
"When did ignorance become a point of view" - Dilbert

Questionwhere the actual file is stored?? Pin
scorp_scorp25-Mar-10 1:05
scorp_scorp25-Mar-10 1:05 
AnswerRe: where the actual file is stored?? Pin
Jörgen Andersson25-Mar-10 1:22
professionalJörgen Andersson25-Mar-10 1:22 
GeneralRe: where the actual file is stored?? Pin
scorp_scorp26-Mar-10 7:22
scorp_scorp26-Mar-10 7:22 
GeneralRe: where the actual file is stored?? Pin
Jörgen Andersson26-Mar-10 9:47
professionalJörgen Andersson26-Mar-10 9:47 
QuestionAudit Trail and Entity Framework Pin
andreas.schaerer25-Mar-10 0:05
andreas.schaerer25-Mar-10 0:05 
AnswerRe: Audit Trail and Entity Framework Pin
Mycroft Holmes25-Mar-10 0:44
professionalMycroft Holmes25-Mar-10 0:44 
AnswerRe: Audit Trail and Entity Framework Pin
David Skelly25-Mar-10 3:18
David Skelly25-Mar-10 3:18 
AnswerRe: Audit Trail and Entity Framework Pin
scottgp25-Mar-10 3:33
professionalscottgp25-Mar-10 3:33 
QuestionOracle encryption/decryption Pin
StanlyJose24-Mar-10 5:34
StanlyJose24-Mar-10 5:34 
AnswerRe: Oracle encryption/decryption Pin
Luc Pattyn24-Mar-10 5:46
sitebuilderLuc Pattyn24-Mar-10 5:46 
AnswerRe: Oracle encryption/decryption Pin
Don Burton24-Mar-10 6:10
Don Burton24-Mar-10 6:10 
Questionsql conctante first name and last name Pin
netJP12L23-Mar-10 5:46
netJP12L23-Mar-10 5:46 
AnswerRe: sql conctante first name and last name Pin
i.j.russell23-Mar-10 6:01
i.j.russell23-Mar-10 6:01 
AnswerRe: sql conctante first name and last name Pin
Avi Berger23-Mar-10 6:15
Avi Berger23-Mar-10 6:15 
AnswerRe: sql conctante first name and last name Pin
Corporal Agarn23-Mar-10 7:39
professionalCorporal Agarn23-Mar-10 7:39 
Questionplease help me with sql query (fine tune the sql query) Pin
poornas23-Mar-10 4:28
poornas23-Mar-10 4:28 
AnswerRe: please help me with sql query (fine tune the sql query) Pin
PSK_23-Mar-10 4:53
PSK_23-Mar-10 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.