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

  • Home
  • SEARCH
  • 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 4543944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:36:07+00:00 2026-05-21T15:36:07+00:00

How can I change from SID Name Math English French 1 Sam 16 17

  • 0

How can I change from

SID Name Math English French
1   Sam  16   17      19
2   Tom  18   14      12
3   Al   90   33      2

to:

SID subject   Mark
1   Math      16
1   English   17
1   French    19
2   Math      18
2   English   14
2   French    12
3   Math      90
3   English   33
3   French    2  

using SQL (MYsql and MS Access if possible) ?

Thanks.

  • 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-05-21T15:36:08+00:00Added an answer on May 21, 2026 at 3:36 pm
    SELECT sid, 'Math' as subject, math as mark
    FROM your_table
    UNION ALL
    SELECT sid, 'English' as subject, english as mark
    FROM your_table
    UNION ALL
    SELECT sid, 'French' as subject, french as mark
    FROM your_table
    

    But the root cause of your problem is a wrong database design. Those subjects shouldn’t be columns in the first place and should be stored in a table very much like your desired output.

    Edit

    So what does it do?

    SELECT sid, 'Math' as subject, math as mark
    FROM your_table
    

    Returns the sid column, a “virtual” column with the hardcoded value 'Math' that is given the name subject. As you have not stored the value 'Math' somewhere, this had to be hardcoded. Then at last it also selects the column math using the name mark instead. Note the difference between math and 'Math' – one is a column the other one a string literal because of the single quotes.

    This is done for all three subjects (if you had four subjects, you’d need four parts in the UNION)

    The UNION ALL combines all three SELECTs into one single query. andr solution (which has been downvoted by someone who didn’t understand it) makes this even clearer by explicitely putting that into a derived table (or inline view).

    Run each SELECT on its own to see what the individual parts are doing.

    The part as mark is called a “column alias” and can also be used to retrieve columns with the same name from different tables in a join and still have unique names in the result set.

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

Sidebar

Related Questions

How can I change the connection string from nhibernate.config file using nant the problem
I have two view controller classes in my application delegate. I can change from
i created a class derived from CheckedListBox so i can change item height as
Does anyone know how I can change the window state of a form, from
How can I change the current working directory from within a Java program? Everything
I can't change the fontsize in a direct.label (from the directlabels package) ggplot2 plot.
How can i change the implementation of a method at runtime from return false;
instead of popup from center can we change to another animation (eg, undo animation)?
How can I change the color of the alert view box from blue to
from this code will show in original color how can i change it to

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.