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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Query Help

Author  Topic 

miles2smiles
Starting Member

1 Post

Posted - 2010-01-31 : 20:21:01
Hi i am stuck if anyone could help me with a simple a query which seems quiet complex to me
here is the design of my datbase

member_table
member_ id | name | lastname| picture
1 | john| joe | abc.jpg
2 | sue | san | def.jpg
3 | mark| davis | ddd.jpg

comment_ table
member_id| comment| guest id|
1 | hello | 1
1 | hi | 2
2 | test | 2


at i want to do is

i need name + last name from member table to check who has put a comment on member_id in comment table

i think i have not cleared my poinnt but you have the idea of the database this works like who ever puts comment on the comment talbe i need to pull out their information fro member table


here it is what i am trying to do

string insertSql = "SELECT irakleous_member.memberID, irakleous_member.firstname, irakleous_member.picture, irakleous_member.lastname, irakleous_comment.guestID, irakleous_comment.comment, irakleous_comment.commentdate FROM irakleous_member INNER JOIN irakleous_comment ON irakleous_member.memberID = irakleous_comment.guestID AND irakleous_member.memberID = @memberID ORDER BY irakleous_comment.commentdate DESC";

this is commange and structure of my ctuall detailed database table

help plzzzzzzzzzzzzzzz

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-02-01 : 01:33:04
Can you please describe your problem?
Is the query not giving the expected result?
Are there any error messages?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 04:09:16
sounds like this is what you want:-

SELECT irakleous_member.memberID, irakleous_member.firstname, irakleous_member.picture, irakleous_member.lastname, irakleous_comment.guestID, irakleous_comment.comment, irakleous_comment.commentdate,
m2.memberID, m2.firstname, m2.picture, m2.lastname
FROM irakleous_member
INNER JOIN irakleous_comment
ON irakleous_member.memberID = irakleous_comment.memberID
AND irakleous_member.memberID = @memberID
INNER JOIN irakleous_member m2
ON m2.memberID = irakleous_comment.guestID
ORDER BY irakleous_comment.commentdate DESC
Go to Top of Page
   

- Advertisement -