SQL Design Help (self join, sorta)

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Pyrite
Forum Regular
Posts: 769
Joined: Tue Sep 23, 2003 11:07 pm
Location: The Republic of Texas
Contact:

SQL Design Help (self join, sorta)

Post by Pyrite »

I have a table that looks like this (people that play on my game servers):

id|name|ip|guid

And I have a search page, that basically does this:

Code: Select all

$sql = "SELECT id, name, INET_NTOA(ip) AS ip, guid FROM 1up_people WHERE (name LIKE \"%$query%\" OR INET_NTOA(ip) LIKE \"%$query%\" OR guid LIKE \"%$query%\")";
Now, that will let me search by either name, ip, or guid (guid is a unique number to each player per server, and I have 8 servers). Now we know IP addresses tend to change, and players tend to play under a different name on occasion. I would like the search to be able to search other records that match the name, ip or guid from the first query. Is there a way to do that with SQL? So like a search for a player name, and not only get all the records that are LIKE that name, but also all the players with the same IP or GUID. Make sense?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: SQL Design Help (self join, sorta)

Post by Eran »

The query you wrote *will* return all the players who match either the IP, name or guid, so I can't tell what else you are after.
Post Reply