Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 02-11-2013, 12:56 AM
rashidfarooq rashidfarooq is offline
Contributing Member
 
Join Date: 11-16-11
Posts: 103
iTrader: 0 / 0%
Which SQL Statement Can Solve my Problem

I have a two tables with following details

Table 1: tbl_comments
fields: comment_id (Primary Key), comment_text, thread_id, user_id (Foreign Key);

Table 2: tbl_users
fields: user_id (Primary Key), user_name, user_total_posts, user_total_threads;


Suppose There are 5 Comments of a thread (thread_id = 110) in tbl_comments and I want to Select all those comments using (SELECT * FROM tbl_comments WHERE thread_id=110) but the problem is, I also want to get the user_total_posts and user_total_threads data that is in tbl_users on the base of user_id in tbl_comments.

Which SQL Statements can solve my problem, please guide me.
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 02-19-2013, 11:20 AM
nodesolomon nodesolomon is offline
Junior Member
 
Join Date: 02-19-13
Posts: 9
iTrader: 0 / 0%
try doing an INNER JOIN:

SELECT *
from comments
INNER JOIN users
ON comments.user_id = users.id

this hasn't been tested, but its a good start you need to join two tables, let me know if you ned more help
 
Reply With Quote
  #3  
Old 02-22-2013, 02:23 AM
rashidfarooq rashidfarooq is offline
Contributing Member
 
Join Date: 11-16-11
Posts: 103
iTrader: 0 / 0%
Quote:
Originally Posted by nodesolomon View Post
try doing an INNER JOIN:

SELECT *
from comments
INNER JOIN users
ON comments.user_id = users.id

this hasn't been tested, but its a good start you need to join two tables, let me know if you ned more help
Thanks I used this query and it works fine. Thanks a lot.
 
Reply With Quote
  #4  
Old 05-31-2013, 08:35 AM
patricksamson patricksamson is offline
Junior Member
 
Join Date: 05-31-13
Posts: 5
iTrader: 0 / 0%
inner joins should be used with care as it consume high resources
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How Solve this Problem? Kuke V7N Forum Support 1 08-24-2011 08:43 AM
SomeOne solve my problem help plz!!!! aaronsmith Google Forum 15 04-05-2011 12:13 AM
Can anyone solve this problem??? daemon king Forum Lobby 20 09-18-2009 07:20 PM
plz solve my problem lskanya Tech Talk 5 02-04-2006 01:05 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 06:06 PM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC