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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:47:30+00:00 2026-06-07T09:47:30+00:00

Table Class Firstname Lastname mark V John Lim 60 V Wills smith 80 VI

  • 0
Table
Class   Firstname   Lastname    mark
V       John        Lim         60
V       Wills       smith       80
VI      Mark        Bay         75
VI      Carl        mark        65

i have this table in my SQL. I need a single query to retrieve two different XML results based on the “class type” from one table

Below is my expected results

Result1
<Studentslist>
<Students>
        <class>V</class>
        <Firstname>John</Firstname>
        <Lastname>Lim</Lastname>
        <mark>60</mark>
</Students>
<Students>
        <class>V</class>
        <Firstname>Wills</Firstname>
        <Lastname>smith</Lastname>
        <mark>80</mark>
</Students>
</Studentslist>

Result2
<Studentslist>
<Students>
        <class>VI</class>
        <Firstname>Mark</Firstname>
        <Lastname>Bay</Lastname>
        <mark>75</mark>
</Students>
<Students>
        <class>VI</class>
        <Firstname>Carl</Firstname>
        <Lastname>mark</Lastname>
        <mark>65</mark>
</Students>
<Studentslist>

many 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-06-07T09:47:31+00:00Added an answer on June 7, 2026 at 9:47 am

    for query part,use UNION

    (SELECT class, firstname, lastname, mark from students where class='V')
    UNION ALL
    (SELECT class, firstname, lastname, mark from students where class='VI')
    

    EDITED: using cursor

    DELIMITER | 
    Drop procedure if exists `GetData`;
    CREATE PROCEDURE `GetData`()
    
    
    BEGIN
    
    
      DECLARE bDone INT;
      DECLARE var1 CHAR(16);   
    
      DECLARE curs CURSOR FOR  SELECT distinct(class) FROM students;
      DECLARE CONTINUE HANDLER FOR NOT FOUND SET bDone = 1;
    
      SET bDone = 0;
    
      DROP TEMPORARY TABLE IF EXISTS tblResults;
      CREATE TEMPORARY TABLE IF NOT EXISTS tblResults (
        class varchar(255),
        firstname varchar(255),
        lastname varchar(255),
        mark varchar(255)
      );
    
      OPEN curs;
    
    
      emp_loop: LOOP
        FETCH curs INTO var1;
         IF bDone=1 THEN       /* No more rows*/
                  LEAVE emp_loop;
         END IF;
    
        INSERT INTO tblResults SELECT class, firstname, lastname, mark FROM `students` where class=var1;
    
      END LOOP emp_loop;
    
      CLOSE curs;
      SELECT * FROM tblResults;
    END|
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following object: namespace LearnLINQ1 { [Table(Name=testMe)] public class SubmitTest { [Column(Name=FirstName)]
Let's say I have a Person table with a FirstName and LastName column. I
I have the following code in my context, and no explicit table-class mapping, yet
I have a table of class players with 5 columns and 40 rows. I
i have a t_class table in mySql, in this table there are 3 columns,
I have tried to find a table with class data in a web page
Is it possible to put a table class in php, like this: echo <table
with my table. person_id serial NOT NULL, firstname character varying(30) NOT NULL, lastname character
I have Doctrine 2.1 entity: /** * @Entity(repositoryClass=Varlab\Model\Repository\UserRepository) * @Table(name=user) */ class User {
Scenario: I have an insert .php file to insert into applicant table: (columns: firstname

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.