Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9155295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:33:59+00:00 2026-06-17T12:33:59+00:00

i need some query. CREATE TABLE `location_areas_localized` ( `id` int(11) DEFAULT NULL, `lang_index` varchar(5)

  • 0

i need some query.

CREATE TABLE `location_areas_localized` (
  `id` int(11) DEFAULT NULL,
  `lang_index` varchar(5) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  KEY `id` (`id`),
  KEY `lang_index` (`lang_index`),
  KEY `name` (`name`),
  FULLTEXT KEY `name_2` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


INSERT INTO `location_areas_localized` (`id`, `lang_index`,`name`)
VALUES
    (1,'ru','Нью Йорк'),
    (1,'en','New York'),
    (2,'en','Boston'),
    (2,'ch','波士顿')
;

Logic of search.

If row with lang_index='ru' AND id IN(1,2) found. it must return all with lang_index='ru'
If one or more rows with lang_index='ru' not exists But exists with lang_index='en' and with some id.
Then it must return all exists with land_index='ru' AND id IN(1,2) and all that not found with lang_index='ru' but found with lang_index='en' (in table – all rows with lang_index='en' always exists)

See on sqlfiddle

I need only one result per id. I tried GROUP BY id but its not works correctly.

Output must be

  1,'ru','Нью Йорк'

   2,'en','Boston'   (because lang_index='ru' with id 2  not found)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:34:00+00:00Added an answer on June 17, 2026 at 12:34 pm
    SELECT 
      coalesce(max(CASE WHEN lang_index='ru' THEN name ELSE null END), name) as name
    FROM 
      location_areas_localized 
    WHERE 
      id IN (1,2) 
      AND (lang_index='en' OR lang_index='ru')
    group by 
      id
    ORDER BY 
      FIELD(lang_index,'ru','en');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help with a query. I have this simple table: CREATE TABLE
Need some help with a query.. I have three tables. Source id name 1
I am now writing some query's for a cronjob. The query's need to create
I have two tables : create table CurrentDay ( ID int identity primary key,
I have table as below create table myTable (id int, col1 varchar(20), col2 varchar(20),
I need a help with a complicated select query.I have message table CREATE TABLE
I need some help a query. For each movie in my database that has
I am new to SQL Server 2008, and I need some help in query
I need some help with SQL Query. I am trying to select all records
I need some help putting together this query in Django. I've simplified the example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.