Ultrashock Forums > Development > Server Side
mySQL - Select Field Based On Second Field Value?
Member Blogs
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
mySQL - Select Field Based On Second Field Value?
Old 4 Weeks Ago


Sorry about the thread title, it probably doesn't make much sense. I was just wondering if it is possible to select FieldA or FieldB depending on the value of FieldC... all fields are in the same table.

Here is some pseudo code...

Code:
SELECT( `preview` IF `has-preview` ELSE `text` ) AS `output`
So, if `has-preview` is true then `preview` is returned otherwise `text` is returned.


www.si-robertson.com
postbit arrow 1 comment | 282 views postbit arrow Reply: with Quote   
Nutrox
Registered User
Nutrox is offline
seperator
Posts: 10,440
2004-04-25
Age: 30
Nutrox lives in United Kingdom
Nutrox has 1 blog entries1 13
Nutrox's Avatar
seperator

Ultrashock Member Comments:
Nutrox's Avatar Nutrox Nutrox is offline Nutrox lives in United Kingdom 1 Blog Entries 13 Creative Assets 4 Weeks Ago #2 Old  

No problem, I've worked it out.

Code:
SELECT CASE WHEN `has-preview` THEN `preview` ELSE `text` END AS `output`
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: