Domanda

I am trying to create a search engine that filters and preform searches by using values from two tables.

I have managed to create a temporary table by inner joining two tables together. However I cannot figure a way to get the mysql query to search from the temp table.

$search_query = mysql_query("SELECT first_name, last_name, major, location, class_of, campus, avatar, state, country 

FROM ('SELECT users.first_name, users.last_name, users.location, users.country, tags_game.name, tags_interest.name, tags_movie.name FROM users, tags_game, tags_interest, tags_movie WHERE users.id IN (tags_game.relation, tags_interest.relation, tags_movie.relation)')
                somealias

WHERE first_name LIKE '{$first_name}%' && 
    location LIKE '{$location}%' &&     
    state LIKE '{$state}%' &&
    country LIKE '{$country}%' 

However this doesn't work. How do I use/call temp tables inside other queries?

È stato utile?

Soluzione

The subquery needs an alias name otherwise it won't work. This returns 1 :

SELECT test from  -- or fully qualified : aliasname.test
  (SELECT 1 as test) aliasname
WHERE test>0

So I presume you require something like :

mysql_query("SELECT something_1, something_2 . . . FROM
  (SELECT table1.something_1, table2.something_2 . . .) somealias WHERE . . .");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top