tags:

views:

98

answers:

2

I have two rating/votes tables. One for user votes and stats and another for external votes. The external votes table always have data because it has a DEAFULT = 0, but the users votes only contains data if any user have voted for that specific ID.

So I do something like this:

    $sql = 'SELECT  ratings_stats.votes, ratings_stats.total_value,
                   ratings_stats.view, ratings_stats.fav, ratings_stats.wish,
                   ratings_external.votes, ratings_external.total_value
            FROM ratings_stats, ratings_external
            WHERE ratings_stats.imdbID = ?
            AND ratings_stats.imdbID = ratings_external.imdbID
            LIMIT 1';

I want to select data from both tables if available OR only form the second (external votes) table if not.

How to can I do it without making a new query?

A: 

Yes it is possible

Grumpy
Thanks for the useful help... ?
Jonathan
+3  A: 
SELECT  ratings_stats.votes, 
        ratings_stats.total_value,
        ratings_stats.view, 
        ratings_stats.fav, 
        ratings_stats.wish,
        ratings_external.votes, 
        ratings_external.total_value
FROM  ratings_external
LEFT JOIN ratings_stats ON ratings_stats.imdbID = ratings_external.imdbID
WHERE ratings_external.imdbID = ?
LIMIT 1
JNK
@JNK: +1 for spotting the correct join condition :-) I've deleted my answer.
Mike