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
Related Q & A:
- How to Map Two Tables To One Class in Fluent NHibernate?Best solution by stackoverflow.com
- How do I compare two tables with the same column definitions in different schemas?Best solution by Database Administrators
- How to select all articles and their similar articles from MySQL?Best solution by Stack Overflow
- Is it possible to conditionally select columns in MySQL?Best solution by Yahoo! Answers
- How can I look at insurance quotes for different cars at one time?Best solution by allstate.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.