Jump to content

querying multiple tables


cosmicsea

Recommended Posts

I am currently using this

 

select keyword from ".$mysql_table_prefix."keywords WHERE keyword like '%{$query}%' LIMIT 5

 

to show 5 related keywords to searches done on my search engine.

 

but I also want to query the table query_log and the query column for results, so I need something like this.

 

select keywords.keyword, query_log.query from ".$mysql_table_prefix."keywords, query_log WHERE keyword and query like '%{$query}%' LIMIT 5

 

I know that does not work but I wanted to show some kind of example of what I am trying to do. how can I get the info from both tables? and is there anything I could add to have more relevant related keyword results if more than 5 exist? Like if I use order by something "something being any sql attribute" can I achieve better results? can anyone help me with this? thanks.

Link to comment
https://forums.phpfreaks.com/topic/222189-querying-multiple-tables/
Share on other sites

Does anybody know how I can turn both of these into 1 query?

 

            $result=mysql_query("select keyword from ".$mysql_table_prefix."keywords WHERE keyword like '%{$query}%' LIMIT 3");
            $result=mysql_query("select query from ".$mysql_table_prefix."query_log WHERE query like '%{$query}%' LIMIT 3");

 

Both of those work fine but I need to make it a single query. Can someone please help?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.