/    Sign up×
Community /Pin to ProfileBookmark

Sql random query

mysql_query(“SELECT * FROM RAND(titles, titles1, titles2) ORDER BY RAND() LIMIT 0,1”)

i know what i did above is probably wrong
but what im trying to do is, select a random table out of the 3 above
and select a random row out of the random table
is there anyways of doing this?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 14.2009 — You'll probably want to select the table in your PHP code, then plug it into the SQL:
[code=php]
$tables = array(
'titles',
'titles1',
'titles2'
);
$table = $tables[array_rand($tables)];
$sql = "SELECT * FROM $table ORDER BY RAND() LIMIT 1";
[/code]
Copy linkTweet thisAlerts:
@robertbarzykauthorOct 14.2009 — haha your a smart guy you seem to answer most of my questions

do u care if i just message you with some of my questions
Copy linkTweet thisAlerts:
@NogDogOct 14.2009 — haha your a smart guy you seem to answer most of my questions

do u care if i just message you with some of my questions[/QUOTE]


Yes, I mind. :p

If I'm doing it for free, I prefer to keep it in public forums; otherwise providing personal services for a fee as part of my freelancing work.
Copy linkTweet thisAlerts:
@robertbarzykauthorOct 14.2009 — darnit okay... haha

well i mean just to let you know im about to be posting a new thread in javascript lol!
Copy linkTweet thisAlerts:
@svidgenOct 14.2009 — I was unaware that this question was double-posted ... I provided an alternate answer it in the SQL thread: http://www.webdeveloper.com/forum/showthread.php?t=218200
×

Success!

Help @robertbarzyk spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...