| Author |
Topic |
|
cutepraba
Yak Posting Veteran
53 Posts |
Posted - 2008-07-28 : 08:08:16
|
| I have three tablesfoldersfolderid foldername userid1 Codes 12 Database 13 Goldscribe 14 Bomb 15 Links 16 email 17 Fun 18 personal 19 personal 210 personal 311 personal 4DATAfileid folderid userid fileno1 1 1 452152 2 1 452163 1 1 452174 4 1 452185 3 1 452196 6 1 452107 7 1 452118 8 1 452129 8 1 45213NetworkUSERID - main useridFUSERID -friends idUSERID FUSERID1 22 21 43 4Now i need to display the files and distinct folders of user 1 friends.Folderid foldername filecount1 Codes 22 dabase 0...........It is confusing me for the past two day. please help Thank you____________Praba |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-28 : 08:11:02
|
Try to write a query that uses a INNER JOIN.What have you tried this far? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
cutepraba
Yak Posting Veteran
53 Posts |
Posted - 2008-07-28 : 08:15:15
|
| I have already been suggested for INNER JOIN, now i am totaly out of contorl betwwen three tables and i am also confused how to relate the userid in Network table.SELECT f.folderid, f.foldername, count(*) AS filecountFROM sffolders AS f INNER JOIN sfurl AS d ON (d.folderid = f.folderid) AND (d.userid = f.userid)WHERE d.userid = 1 GROUP BY f.folderid, f.foldername;____________Praba |
 |
|
|
dexter.knudson
Constraint Violating Yak Guru
260 Posts |
Posted - 2008-07-28 : 08:19:47
|
| Try something like this:SELECT userid, folderid, foldername, count(fileno)FROM DataINNER JOIN Folders ON Folders.folderid = Data.folderidINNER JOIN Network ON Network.userid = Folders.useridWHERE Network.userid = 1GOUP BY userid, folderid, foldernameORDER BY userid, folderid, foldername |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-28 : 08:20:25
|
Something similar to thisSELECT f.FolderID, f.FolderName, COUNT(d.FolderID) -- Just in case there are empty foldersFROM Network AS nINNER JOIN Folders AS f ON f.UserID = n.fUserIDLEFT JOIN Data AS d ON d.FolderID = f.FolderID -- Just in case there are empty folders AND d.UserID = f.fUserIDWHERE n.UserID = 1GROUP BY f.FolderID, f.FolderName E 12°55'05.25"N 56°04'39.16" |
 |
|
|
cutepraba
Yak Posting Veteran
53 Posts |
Posted - 2008-07-28 : 08:39:52
|
| Both codes showing syntax error(missing operator)Infact i dont want the folder tabel. i just want to know.Now i am going with view, i am using MSSQL.____________Praba |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-28 : 15:23:46
|
Are you sure you are using MICROSOFT SQL SERVER? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-28 : 21:03:46
|
quote: Originally posted by cutepraba Both codes showing syntax error(missing operator)Infact i dont want the folder tabel. i just want to know.Now i am going with view, i am using MSSQL.____________Praba
Post the full error message KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|