Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
DesiGal
Starting Member
31 Posts |
Posted - 2009-10-20 : 13:45:05
|
| Consider I have 4 tables as followsBooks(BookId,Name,AuthorId)Books_Comments(BookId,CommentId)Comments(CommentId,comment,CreatedAt)Authors(AuthorId,AuthorName)A single book can have many commentsselect Books.BookId,Books.Name,Authors.AuthorName,Comments.commentfrom Books inner join Books_Comments.BookId=Books.BookIdinner join Comments on Comments.CommentId=Books_Comments.CommentIdinner join Authors on Authors.AuthorId=Books.AuthorIdwhere Authors.AuthorName='ABC'I am looking for a query which returns me the last entered comment for the books. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-20 : 13:52:45
|
| [code]select Books.BookId,Books.Name,Authors.AuthorName,Comments.commentfrom Books inner join (select BookId,MAX(CommentId) AS Latestfrom Books_Comments group by BookId)bcon bc.BookId=Books.BookIdinner join Comments on Comments.CommentId=bc.Latestinner join Authors on Authors.AuthorId=Books.AuthorId[/code] |
 |
|
|
DesiGal
Starting Member
31 Posts |
Posted - 2009-10-20 : 14:17:56
|
| Thanks Visakh16 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-10-20 : 14:20:25
|
| welcome |
 |
|
|
leah
Starting Member
2 Posts |
Posted - 2009-10-20 : 14:28:01
|
| Hi...I had a sql question...I want to do something in sql....like this... I have a sql data source and I pass 1 parameters if id = chani but 2 parameters if id = malka and if id = malka then parameterA is for sure NOT NULL, soo I wanted to do something like this, but I think it's wrong...could you direct me maybe?? @parameterA int , @parameterB char(12), ASBEGINSET NOCOUNT ON;IF @parameterA is not NULL --malka BEGINSELECT * FROM MalkaWHERE parameterA = @parameterA AND parameterB=@parameterB ORDER BY enteredDate DESC ENDELSE -- if chani BEGINSELECT myname, * FROM chaniWHERE parameterB = @parameterBENDEND |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-10-20 : 14:30:13
|
Leah,Don't hijack someone else's thread. Start a new thread, you'll get better results that way as well. JimEveryday I learn something that somebody else already knew |
 |
|
|
|
|
|
|
|