Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-11-2009
Member
 
Join Date: Jun 2009
Posts: 3,859
Sql query with join

Here are the structure of my tables

Comments
--------------
id auto_increment
date
Comment

comment_member
------------------
cm_id_comment
cm_id_member

User
---------------------
id auto_increment
username
.....

I wish I could retrieve the list of user reviews. I then test to make a request to retrieve my comments for user with id 1.

Here are the data in the database.

Comments
--------------------

1 2009-11-06 11:26:52 comments for user1
2 2009-11-05 11:27:11 comments for user2

comment_member
----------------------
1 1
2 2

User
-----------------
1 user1
2 user2
Reply With Quote
  #2  
Old 06-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Sql query with join

But what you have tried? And by the way, your table comment_member has no interest, directly put the id of the member in the table comment.
Reply With Quote
  #3  
Old 06-11-2009
Member
 
Join Date: Jun 2009
Posts: 3,859
Re: Sql query with join

If it has an interest because I have to differentiate the comments of a member or group.

If I tried that
Code:
SELECT * FROM 'comment'
INNER JOIN  'comment_member'
ON comment_member.cm_id_member= 1
But this returns me to the second user feedback too.
Reply With Quote
  #4  
Old 06-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Sql query with join

You did not do that with JOIN on the right field; the common field in both tables is the id of the comment. Your id_member = 1 will be in the WHERE clause.
Reply With Quote
  #5  
Old 06-11-2009
Member
 
Join Date: Jun 2009
Posts: 3,859
Re: Sql query with join

Like this then?

Code:
SELECT *
FROM 'comment'
INNER JOIN 'comment_member' ON comment_member.cm_id_member = comment.id
WHERE cm_id_member =1
Reply With Quote
  #6  
Old 06-11-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: Sql query with join

Didn't you thought on this for atleast 30 seconds! Why would your id_member be equal to the id of the comment?
Reply With Quote
  #7  
Old 07-11-2009
Member
 
Join Date: Jun 2009
Posts: 3,859
Re: Sql query with join

Sorry for that but I am addicted to copy (CTRL + C) and paste (CTRL + V)

Anyways then the code would be like this:
Code:
SELECT *
FROM `comment`
INNER JOIN `comment_member` ON comment_member.cm_id_comment = comment.id
WHERE cm_id_member =1
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Sql query with join"
Thread Thread Starter Forum Replies Last Post
Can?t join friends in Max Payne 3, error "Join Failed Failure: Blacklisted. G.Kahli Video Games 3 02-06-2012 12:44 PM
Join two tables using SQL query vaib288932 Software Development 3 20-08-2010 12:01 PM
How to Create view based on table-join query Preetish Windows Software 3 12-08-2009 01:44 PM
Turn on MySQL query cache to speed up query performance DMA2Superman Software Development 3 07-07-2009 10:26 AM
Equi Join vs Natural Join in SQL Demetrius Software Development 3 14-05-2009 12:55 PM


All times are GMT +5.5. The time now is 02:42 PM.