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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:31:26+00:00 2026-06-16T04:31:26+00:00

I Have Two Tables Table1 HTNO SUBJECTCODE INTERNALS EXTERNALS TOTAL 1 s1 20 58

  • 0

I Have Two Tables

Table1

 HTNO          SUBJECTCODE          INTERNALS          EXTERNALS            TOTAL
   1               s1                   20                  58                 78
   1               s2                   15                  20                 35
   1               s3                   10                  60                 70 
   2               s1                   10                  20                 30
   2               s2                   12                  30                 42
   2               s3                   15                  55                 70
   .
   .
   .
   so on up to N

Table 2

  SUBJECTCODE             SUBJECT NAME
       s1                    MATHS
       s2                   SCIENCE
       s3                    SOCIAL

I will be giving a form for student to enter the hallticket Number

If student Enters 1 in form then the result should be

   Subjectcode        SubjectName        Internals       Externals        Total
       s1                Maths              20              58              78
       s2               Science             15              20              35
       s3                Social             10              60              70

The above should be the output

But Here I am unable to retrieve SubjectName from Table2 in the result

And here is my code which i am using

    <?PHP
    $userInputEntities = htmlentities($userInput);
    echo $userInputEntities;

    $username = "admin";
    $password = "123456";
    $database = "test";
    $server = "localhost";
    $db = new PDO ("mysql:host=$server;dbname=$database", "$username", "$password");

    if ($db) {
    $id = $_GET['id'];
    $SQL = $db->prepare("SELECT * FROM Table1 WHERE htno = :id");
    $SQL -> execute(array(':id'=>$id));
    $n = $SQL->rowCount();
    echo "
    <center><table class='dynamic styled with-prev-next' data-table-tools='{'display':true}' align=center>
    <thead>
    <tr>
    <TH class='table-header dark' scope='col'>SUBJECT CODE</TH>
    <TH class='table-header dark' scope='col'>SUBJECT NAME</TH>
    <TH class='table-header dark' scope='col'>INTERNALS</TH>
    <TH class='table-header dark' scope='col'>EXTERNALS</TH>
    <TH class='table-header dark' scope='col'>TOTAL</TH>

    </tr></thead><center>";          

    while ($db_field = $SQL->fetch(PDO::FETCH_ASSOC)) {


    echo "<tr><tbody>";
    echo "<td align=center>" . $db_field['SubjectCode'] . "</td>";

     echo "<td align=center>" . $db_field['Internals'] . "</td>";
   echo "<td align=center>" . $db_field['Externals'] . "</td>";
   echo "<td align=center>" . $db_field['Total'] . "</td>";

   echo "</tbody></tr>";

   }

with this code i am unable to get SUbject Name for a particualr subject code of a student
actually i have nt written any code to retrieve dubject name from Table2, I dont Know How to write it

Please Help me

  • 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-16T04:31:27+00:00Added an answer on June 16, 2026 at 4:31 am

    It looks like you need a SQL statement that will retrieve the resultset you want:

    SELECT t1.SubjectCode
         , t2.SubjectName
         , t1.Internals
         , t1.Externals
         , t1.Total
      FROM Table1 t1
      JOIN Table2 t2
        ON t2.SubjectCode = t1.SubjectCode
     WHERE t1.htno = :id
    

    To have the rows returned in a predictable order, you can include an ORDER BY clause in the query text, following the WHERE clause:

    ORDER
       BY t1.htno
        , t1.SubjectCode
    

    Q: “Before the result was faster but now it is taking much time to display the result – can u tell me y if u know the reason ?”

    A: No, I don’t have enough information to determine the exact reason for the slow performance of the new statement. But I can give you some likely possibilities.

    (I have to tell you though, that I am hesitant to respond to your query, since you have already “selected” an answer to your question.)

    The most likely explanation for the slow performance is that you do not have appropriate indexes defined on your tables. And the most likely candidate indexes (for best performance of your query) would be:

    ... Table2_IX1 ON Table2 (SubjectCode, SubjectName)
    

    and

    ... Table1_IX1 ON Table1 (htno, SubjectCode, Internals, Externals, Total)
    

    On Table, at a minimum, you want an index that has a leading column of htno, since your query includes an equality predicate (i.e. WHERE htno = 'literal constant'.

    And it would be beneficial to have the next column in that same index be SubjectCode, especially if you specify ORDER BY t1.SubjectCode (or ORDER BY t1.htno, t1.SubjectCode) in your query, since MySQL can make use of that index, and bypass a “filesort” operation that would otherwise be required.

    If you also include all of the other columns from Table1 that are referenced by your query, then you would have a “covering” index. That means that MySQL can obtain all of the data in needs directly from the index pages, without having to visit the pages of the underlying table.

    On Table2, at a minimum, you want an index with a leading column of SubjectCode. That will allow MySQL to use that index to satisfy the join predicate. If that same index also includes theSubjectName` column, then that index would also be a “covering” index for your query, and MySQL could satisfy the query entirely from the index, without a need to visit any pages in the underlying table.

    To really evaluate which indexes will give the best performance, you’d need to EXPLAIN your query, and take a look at the access paths. It’s likely that the best performance of this query will be obtained when the Extra column in the EXPLAIN output shows “Using index”.

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

Sidebar

Related Questions

I have two tables table1 +-------+-------+ | NAME | PRICE | +-------+-------+ | ITEM1
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
I have two tables in my MySQL database (table1 and table 2). I want
I have two tables and the following query: table1 --------- table1Id(pk) fromdate, todate, name,
I have two tables - Table1: id name number ------------------ 1 x1 123 2
I have two tables: Table1: id attr1 fk1(Table2) fk2(Table2) Table2: id name I want
I have two tables table1: { id, name } table2: { id, table1_id, time_added
i have two different tables table1 - property ================= id,name, address, city state, zip
Dear stackoverflow experts, I have two tables table1<-read.table(table1.txt,header=TRUE) table2<-read.table(table2.txt,header=TRUE) I want to select from
i have two tables Table1 with columns user_name,Password and course ID and another table

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.