Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Mar 23rd, 2008, 7:13 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
MySQL - Basic Combining Of Queries

What I need to do is output a table of matches. But at the same time, I need the username of each user_id found in the table.

So I have:

MySQL Syntax (Toggle Plain Text)
  1. SELECT * FROM $table_match

That fetches every row from the matches table. The matches table has the columns 'user_id1' and 'user_id2'. I want the username for each of these user_ids.

This can be done by calling the following two queries for each row fetched with the above query.

MySQL Syntax (Toggle Plain Text)
  1. SELECT name FROM $table_user WHERE user_id=$user_id1
  2. SELECT name FROM $table_user WHERE user_id=$user_id2

This works, but the problem with that is it will keep querying for usernames, even if it's already fetched it before. Despite MySQL's cache, I feel that this is slower than it needs to be. Maybe MySQL will optimize the query if I combine the two. Or even better, can I link the user_id column to the name column from the user table?

Thanks in advance.
Sane is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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
Connecting MySQL and PHP titaniumdecoy PHP 10 Feb 25th, 2008 7:47 PM
BASIC - the best sort... HippyVanMan Other Programming Languages 6 Sep 23rd, 2007 7:03 PM
The basic of basic in programming... Simongcc Software Design and Algorithms 4 Aug 16th, 2007 3:34 AM
Tutorial - Using MySQL in C# Darkhack C# 12 Jan 17th, 2006 9:28 AM
[ANN] New script engine (Basic sintax) MKTMK C++ 3 Sep 1st, 2005 5:51 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC