Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

mysql conditional selects

Quote Reply
mysql conditional selects
Can MYSQL queries include conditional statements such as:

select 3, order by live_date UNLESS (pick out the top row, if its live_date != todays_date) then select 3, order by random?
Quote Reply
Re: [scorpioncapital] mysql conditional selects In reply to
Something like this?

$DB->table('Links')->select( ['3'], GT::SQL::Condition->new('live_date','!=','todays_date') ) || die $GT::SQL::error;

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] mysql conditional selects In reply to
Not exactly, more like, if today's date is equal to Live_date of the latest record(s) when ORDERED by live_date, continue, otherwise get 'n' random records. I.e. we don't know the live_date a priori, I suppose this requires two calls right - one to get the live_date and compare it, and then to pull either those records or a random one, maybe it can be done in 1 but can't figure it