April 4, 2010 at 10:53 pm
Hi All,
I have two tables table1 and table2.
table1
PostID | UserID |Title | Replies
10 | sta | x | 0
16 | sta | x | 0
table2
UserID | PostID | PostDATE
sta 10 2010-03-15 13:39:43.917
sta 16 2010-03-17 15:05:55.273
sta 16 2010-03-17 15:10:09.500
I have to take table1.PostID,table1.Title,table1.Replies table2.UserID,table2.PostDate
how could i do this?. Pls anyone help i am new to SP
[font="Times New Roman"]Thanks & Regards
Stalin.D[/font]
April 4, 2010 at 11:14 pm
This seems to a basic INNER JOIN query. Look for INNER JOIN in Google or Books Online. Try some code on your own and if you have any further difficulties, get back to us with the code you tried. We will help you in solving the difficulties. We writing the code for you is not going to get you anywhere. Good Luck:-)
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 4, 2010 at 11:21 pm
Hi
Thanks for your Reply.
I have tried the code below but, i am getting duplicate rows
"SELECT table1.PostID,
table1.Title ,table1.UserID,table2.UserId AS Name,table1.Replies,table2.PostDate,
FROM dbo.tbl1 table1 ,dbo.tbl2 table2
WHERE table1.UserID = table2.UserID
and table1.Category = @strCategory
ORDER BY table2.PostDate DESC "
[font="Times New Roman"]Thanks & Regards
Stalin.D[/font]
April 4, 2010 at 11:30 pm
Use Two Condtion With AND LIKE
WHERE table1.UserID = table2.UserID AND table1.PostID= table2.PostID
April 4, 2010 at 11:37 pm
From your post it seems PostID is the primary key in table1 and foreign key in table2. If it is so you should join on PostID column.
Your code should look something like this
SELECTtable1.PostID, table1.Title, table1.UserID, table2.UserId AS Name, table1.Replies, table2.PostDate
FROMdbo.tbl1 table1
INNER JOIN dbo.tbl2 table2
ON table1.PostID = table2.PostID
AND table1.Category = @strCategory
ORDER BY table2.PostDate DESC
Note the use of INNER JOIN. This is a better method of joining two tables. The syntax used by you is the old ANSI syntax and might give errors if the database is set to higher levels of compatibility.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 5, 2010 at 12:22 am
Hi Kingston
Thanks for your reply. I got a clear path towards my result thanks, still i have to move forward to achieve my result.
[font="Times New Roman"]Thanks & Regards
Stalin.D[/font]
April 5, 2010 at 12:35 am
🙂 Glad i could help you. Happy coding.
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply