Skip to main content
added 1447 characters in body
Source Link
ejj
  • 33
  • 4
  • news_id int (PK)
  • category int (FK)
  • rating tinyint
  • news_detail_id int (PK)
  • news_id int (FK)
  • language_code char
  • news_title varchar
  • news_detail text

 

Sample data;

News


news_id  |  category  |  rating
--------------------------------
   1     |     1      |    3
   2     |     3      |    4
   3     |     2      |    5
   4     |     1      |    1
   5     |     2      |    5

News Detail


news_detail_id  |  news_id  |  lang_code | news_title | news_details
--------------------------------------------------------------------
      1         |     1     |    EN      | Title1 Eng | Detail 1 Eng
      2         |     1     |    GER     | Ger Titel  | Deutsch detail 1
      3         |     2     |    EN      | Title2 Eng | Detail 2 Eng
      4         |     3     |    EN      | Title3 Eng | Detail 3 Eng
      5         |     4     |    GER     | Ger Titel4 | Deutsch detail 4
      6         |     5     |    GER     | Ger Titel5 | Deutsch detail 5
---------

Expected Output

----------

news_id  |  rating  |  lang_code | news_title | news_details
-------------------------------------------------------------
   1     |    3     |     GER    | Ger Titel  | Deutsch detail 1
   2     |    4     |     EN     | Title2 Eng | Detail 2 Eng
   3     |    5     |     EN     | Title3 Eng | Detail 3 Eng
   4     |    1     |     GER    | Ger Titel4 | Deutsch detail 4
   5     |    5     |     GER    | Ger Titel5 | Deutsch detail 5
  • news_id (PK)
  • category
  • news_detail_id (PK)
  • news_id (FK)
  • language_code
  • news_title
  • news_detail

 
  • news_id int (PK)
  • category int (FK)
  • rating tinyint
  • news_detail_id int (PK)
  • news_id int (FK)
  • language_code char
  • news_title varchar
  • news_detail text

Sample data;

News


news_id  |  category  |  rating
--------------------------------
   1     |     1      |    3
   2     |     3      |    4
   3     |     2      |    5
   4     |     1      |    1
   5     |     2      |    5

News Detail


news_detail_id  |  news_id  |  lang_code | news_title | news_details
--------------------------------------------------------------------
      1         |     1     |    EN      | Title1 Eng | Detail 1 Eng
      2         |     1     |    GER     | Ger Titel  | Deutsch detail 1
      3         |     2     |    EN      | Title2 Eng | Detail 2 Eng
      4         |     3     |    EN      | Title3 Eng | Detail 3 Eng
      5         |     4     |    GER     | Ger Titel4 | Deutsch detail 4
      6         |     5     |    GER     | Ger Titel5 | Deutsch detail 5
---------

Expected Output

----------

news_id  |  rating  |  lang_code | news_title | news_details
-------------------------------------------------------------
   1     |    3     |     GER    | Ger Titel  | Deutsch detail 1
   2     |    4     |     EN     | Title2 Eng | Detail 2 Eng
   3     |    5     |     EN     | Title3 Eng | Detail 3 Eng
   4     |    1     |     GER    | Ger Titel4 | Deutsch detail 4
   5     |    5     |     GER    | Ger Titel5 | Deutsch detail 5
improved formatting, removed a tag from the title
Source Link
Andriy M
  • 23.2k
  • 6
  • 59
  • 103

MySQL Select another row if NULL

In a MySQL database I have these tables:

Table 1: News

  • news_idnews_id (PK)
  • categorycategory

Table 2: News Detail

  • news_detail_idnews_detail_id (PK)
  • news_idnews_id (FK)
  • language_codelanguage_code
  • news_titlenews_title
  • news_detailnews_detail

All news have an English translation. In German language some of the translations are missing. Now when I query all news in German language, I want to get English translated row if German translation is missing.

Is there a way to accomplish this?

MySQL Select another row if NULL

In a MySQL database I have these tables:

Table 1: News

  • news_id (PK)
  • category

Table 2: News Detail

  • news_detail_id (PK)
  • news_id (FK)
  • language_code
  • news_title
  • news_detail

All news have an English translation. In German language some of the translations are missing. Now when I query all news in German language, I want to get English translated row if German translation is missing.

Is there a way to accomplish this?

Select another row if NULL

In a MySQL database I have these tables:

Table 1: News

  • news_id (PK)
  • category

Table 2: News Detail

  • news_detail_id (PK)
  • news_id (FK)
  • language_code
  • news_title
  • news_detail

All news have an English translation. In German language some of the translations are missing. Now when I query all news in German language, I want to get English translated row if German translation is missing.

Is there a way to accomplish this?

deleted 29 characters in body; edited title
Source Link
Tom V
  • 15.7k
  • 7
  • 64
  • 87

MySql MySQL Select another row if NULL

In MySql dba MySQL database I have these tables;tables:

Table 1: News

  • news_id (PK)
  • category

Table 2: News Detail

  • news_detail_id (PK)
  • news_id (FK)
  • language_code
  • news_title
  • news_detail

All news have englishan English translation. In germanGerman language some of the translations are missing. Now when I query all news in germanGerman language, I want to get englishEnglish translated row if germanGerman translation is missing. 

Is there a way to accomplish this?

Any help would be appreciated, thanks.

MySql Select another row if NULL

In MySql db I have these tables;

Table 1: News

  • news_id (PK)
  • category

Table 2: News Detail

  • news_detail_id (PK)
  • news_id (FK)
  • language_code
  • news_title
  • news_detail

All news have english translation. In german language some of the translations are missing. Now when I query all news in german language, I want to get english translated row if german translation is missing. Is there a way to accomplish this?

Any help would be appreciated, thanks.

MySQL Select another row if NULL

In a MySQL database I have these tables:

Table 1: News

  • news_id (PK)
  • category

Table 2: News Detail

  • news_detail_id (PK)
  • news_id (FK)
  • language_code
  • news_title
  • news_detail

All news have an English translation. In German language some of the translations are missing. Now when I query all news in German language, I want to get English translated row if German translation is missing. 

Is there a way to accomplish this?

Source Link
ejj
  • 33
  • 4
Loading