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 8452313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:28:03+00:00 2026-06-10T11:28:03+00:00

NOTICE: this question has a ambiguous concept about ‘degree’. and I have got my

  • 0

NOTICE: this question has a ambiguous concept about ‘degree’. and I have got my answer already.

These days I am struggling with a question like below: you can’t write a function using some programming language; use RAW SQL only.

Given a table articles which contains 2 columns: article_id and tag_name

article_id  |  tag_name
---------------------------
1              C++
1              java
1              python
2              ruby
2              js
3              ruby
4              java
4              python

and an empty table named ‘tag_relations’ having a structure like:

tag1     |   tag2    |  degree
-----------------------------------

NOW, the question comes:

  • Write a “RAW SQL” to write values to the table ‘tag_relations’ according to the first table’s content.

For the given data, the output should look like ( I am not sure what the degree is, and the question hasn’t mentioned about that, so, both the answers from Gordon Linoff and Jonathan Leffler are correct to me. ) :

tag1     |   tag2    |  degree
-----------------------------------
java         C++        2
java         python     4
ruby         js         2

UPDATED ADDITIONAL info

NOTE 1. Here the ‘degree’ was not described by the question. However I think it’s a measure for the relationships between 2 tags. Since there are values for ‘java’ and ‘C++’:

article_id  |  tag_name
---------------------------
1              C++
1              java

so the degree = 2

and for ‘java’ and ‘python’

article_id  |  tag_name
---------------------------
1              java
1              python
4              java
4              python

so the degree = 4

NOTE 2:
There’s no record for degrees with: ‘python’ and ‘C++’, (I mean this question doesn’t refer to the cases that degree < 2) (Note by editor: this comment is inconsistent with including C++ and Java in the output.)

I have spent a day on this question, and reviewed my knowledge on SQL, but still don’t know how to store variables or loop the records.

Any idea will be appreciated!

  • 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-10T11:28:04+00:00Added an answer on June 10, 2026 at 11:28 am

    What is the degree? It appears to be the maximum article id connecting two things.

    This query requires a self join (and an insert):

    insert into tag_relations(tag1, tag2, degree)
        select a1.tag_name, a2.tag_name, max(article_id) as maxid
        from articles a1 join
             articles a2
             on a1.article_id = a2.article_id and
                a1.tag_name < a2.tag_name
        group by a1.tag_name, a2.tag_name
    

    The self join finds all pairs of items with the same article_id. The “<” just makes sure that reversing the order does not create a new pair. For any pair, the maximum article_id is taken as the new degree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK I have this function (I got as the answer to this question )
I have a very novice question, so apologies if the answer to this is
I notice this question has been asked a few times but I don't really
I think this question is very usual. Many results on Stackoverflow has said about
I know this question has been asked many times and we have gotten this
I hope this question has an obvious answer to anyone who knows his way
Notice: This question is obsolete; the interface declaration syntax has been removed from Dart:
This question has been asked before - but with no satisfying answer at all!
I didn't notice this question on the site already and I am having a
This question was asked already, but the accepted answer is not helpful as the

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.