How to arbitrariarly sort MySQL result set?

MySQL SELECT from different tables into one result set?

  • Hello, I have a jQuery autocomplete "search" input. So you can type in something and it will suggest you results from a MySQL database. Now I have two tables in that database; table 'aliases' with columns 'alias', 'steamid', 'timesused' and table 'ips' with columns 'steamid' and 'ip'. How do I select 'alias', 'steamid', and 'ip' using a LIKE statement on each? That's how it looks like when just using a simple query to get wildcard suggestions for autocomplete when only targetting 'alias' in 'aliases' table. include('../mysql.php'); $db = new MySQL(); $input = $_GET['q']; $db->query("SELECT alias AS alias FROM aliases WHERE alias LIKE '%".$input."%'"); $nicks = $db->fetch(); $nicks = $db->arrayUnique($nicks); foreach($nicks AS $nick) { echo $nick['alias'] . "\n"; } How does the query have to look like to get results per wildcard for columns 'ip', 'alias' and 'steamid'? Regards

  • Answer:

    I *think* this is what you are after, but not positive (and it's definitely untested): SELECT alias,steamid,ip FROM aliases JOIN ips USING(steamid) WHERE alias LIKE '%".$input."%'"

Alexej at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.