What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » MySQL and PHP - using 2 tables in one query?

MySQL and PHP - using 2 tables in one query?
Author: Message:
Adeptus
Senior Member
****


Posts: 732
Reputation: 40
Joined: Oct 2005
RE: MySQL and PHP - using 2 tables in one query?
quote:
Originally posted by Jimbo
I have two tables, Table A that stores just SteamID, with some other fields, and then, another Table B that stores Player name, SteamID and then some other fields.

What I currently have setup is some PHP to query Table A with an entered SteamID, to output all the other fields.

What I am looking to do, is allow someone to enter a name, this then finds the SteamID corresponding to that name in Table B, then searches Table A using this steamid.
quote:
Originally posted by Jimbo
About that query, I really do want to get everything from table A, but only steamid and playername from table B. I then want to be able to search via player name, and return all values from Table A, that relate to this player name's steamid.

The query that MeEtc provided should basically do then, except you want to modify the WHERE clause a bit:

SELECT a.*, b.playername
FROM tableA a INNER JOIN tableB b ON a.steamid = b.steamid
WHERE b.playername = 'Johnny'

Although you said you wanted steamid from tableB, it would presumably be the same coming from tableA and you don't need it in your output twice.  You can use = for an exact name match, or LIKE, as in MeEtc's example, for a partial name match.

Going by the questions I've seen you post over time (which, of course, is perfectly fine), I think you should spend some time reading first some general SQL tutorials, perhaps followed by MySQL documentation, and just play around with some tool that allows you to enter and execute queries and view results.  You are in the same boat many other web developers are -- you don't know how to do much beyond "SELECT *", so that's what you end up doing and then process your results with various kludges.  SQL is awesome.  It can do all of that work for you, you just need to know how to ask it properly.  :)

This post was edited on 01-17-2010 at 07:32 PM by Adeptus.
01-17-2010 07:24 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 01:32 AM
RE: MySQL and PHP - using 2 tables in one query? - by MeEtc on 01-17-2010 at 03:05 AM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 01:51 PM
RE: MySQL and PHP - using 2 tables in one query? - by stoshrocket on 01-17-2010 at 04:41 PM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 04:48 PM
RE: MySQL and PHP - using 2 tables in one query? - by stoshrocket on 01-17-2010 at 05:23 PM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 05:33 PM
RE: MySQL and PHP - using 2 tables in one query? - by Adeptus on 01-17-2010 at 07:24 PM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 07:33 PM
RE: MySQL and PHP - using 2 tables in one query? - by Chrissy on 01-17-2010 at 07:55 PM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 07:57 PM
RE: MySQL and PHP - using 2 tables in one query? - by Chrissy on 01-17-2010 at 08:04 PM
RE: MySQL and PHP - using 2 tables in one query? - by Adeptus on 01-17-2010 at 08:13 PM
RE: MySQL and PHP - using 2 tables in one query? - by MeEtc on 01-17-2010 at 08:15 PM
RE: MySQL and PHP - using 2 tables in one query? - by Matti on 01-17-2010 at 08:19 PM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 08:39 PM
RE: MySQL and PHP - using 2 tables in one query? - by Adeptus on 01-17-2010 at 08:55 PM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-17-2010 at 09:16 PM
RE: MySQL and PHP - using 2 tables in one query? - by Adeptus on 01-17-2010 at 09:22 PM
RE: MySQL and PHP - using 2 tables in one query? - by NanaFreak on 01-18-2010 at 01:49 AM
RE: MySQL and PHP - using 2 tables in one query? - by Jimbo on 01-18-2010 at 01:44 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On