List:General Discussion« Previous MessageNext Message »
From:Rhino Date:January 14 2005 1:56pm
Subject:Re: Selecting a random record from more than 1 table
View as plain text  
----- Original Message ----- 
From: "Christian Biggins" <christian@stripped>
To: <mysql@stripped>
Sent: Friday, January 14, 2005 12:07 AM
Subject: Selecting a random record from more than 1 table


> Hi Guys
>
> I am trying to display 1 random record taken from 2 tables.
>
> I have tried the following;
>
> SELECT table1.record1, table1.record2, table2.record1 FROM table1, table2
> ORDER BY RAND() Limit 1
>
> With no luck... So now I am trying to use CREATE VIEW but also with no
> luck... Can anybody help out?
>
Your question isn't very clear; I can't make out what you are trying to do.
Can you explain in a bit more detail?

It sounds like you are trying to do a join of two tables which selects all
records from both which match and then choose one of the resulting records
at random. But, if that is true, your query contains a bad join because it
is actually going to join every row of Table1 with every row of Table2 *even
if they haven nothing in common*.

I'm not sure why you want to create a view either.

Also, what version of MySQL are you using? Some things can't be done at all
in some versions of MySQL....

Rhino

Thread
Will "Alter Table ... enable keys" reload data to table?mos14 Jan
RE: Will "Alter Table ... enable keys" reload data to table?Dathan Pattishall14 Jan
  • RE: Will "Alter Table ... enable keys" reload data to table?mos14 Jan
    • Selecting a random record from more than 1 tableChristian Biggins14 Jan
      • Re: Selecting a random record from more than 1 tableRhino14 Jan
Re: Selecting a random record from more than 1 tableRhino14 Jan