Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2009, 07:40 PM   PM User | #1
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
get altenate data if there is no demanded data

data, for 'en' there is always data.
Code:
1   en   dog
1   sl    pes
2   en   peacock
....
1.get all for 'it' from that data, and if it does not exist get 'en' -->
1 dog
2 peacock

2.get all for 'sl' from that data, and if it does not exist get 'en'-->
1 pes
2 peacock

query that would do all that provided one parameter 'en','it',or 'sl', or any other language ?

Last edited by BubikolRamios; 02-17-2009 at 06:01 AM..
BubikolRamios is offline   Reply With Quote
Old 02-17-2009, 12:55 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,188
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Hmmm...a fun one!

First thing I would try off the top of my head (UNTESTED!) would be
Code:
SELECT W.id, IF( SL.id IS NULL, W.word, SL.word ) AS TheWord
FROM words AS W 
LEFT JOIN ( SELECT id, language, word FROM words WHERE language = 'sl' ) AS SL
ON W.id = SL.id
WHERE W.id IN ( 1, 2 )
Again, untested (I don't have MYSQL on this machine...don't ask why not), but feels right.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
BubikolRamios (02-17-2009)
Old 02-17-2009, 05:37 AM   PM User | #3
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
excelent !

small correction:
Code:
SELECT W.id, IF( SL.id IS NULL, W.word, SL.word ) AS TheWord
FROM words AS W 
LEFT JOIN ( SELECT id, language, word FROM words WHERE language = 'sl' ) AS SL
ON W.id = SL.id
WHERE W.language = 'en'

PS

Lately I 'm writing qustions that nobody knows the answer, or ..... are fun (-:

Glad that there are people outthere finding my questions interesting.

Last edited by BubikolRamios; 02-17-2009 at 05:39 AM..
BubikolRamios is offline   Reply With Quote
Old 02-17-2009, 07:11 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,188
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Whoops...nice catch on the need for the WHERE clause there.

Well, I did say it was untested. Sorry!
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:48 PM.


Advertisement
Log in to turn off these ads.