|
| |||||||||
| Tags: join, sql, sql query |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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 |
|
#2
| ||||
| ||||
| 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. |
|
#3
| |||
| |||
| 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 |
|
#4
| ||||
| ||||
| 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. |
|
#5
| |||
| |||
| 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 |
|
#6
| ||||
| ||||
| 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? |
|
#7
| |||
| |||
| 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 |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Sql query with join" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Join two tables using SQL query | vaib288932 | Software Development | 3 | 20-08-2010 01:01 PM |
| How to Create view based on table-join query | Preetish | Windows Software | 3 | 12-08-2009 02:44 PM |
| Turn on MySQL query cache to speed up query performance | DMA2Superman | Software Development | 3 | 07-07-2009 11:26 AM |
| Equi Join vs Natural Join in SQL | Demetrius | Software Development | 3 | 14-05-2009 01:55 PM |
| User dis-join from domain, how to re-join again | Newbie | Active Directory | 6 | 18-03-2009 09:35 AM |