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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:53:40+00:00 2026-05-25T15:53:40+00:00

I have 2 tables, a master table and a transaction table. I want to

  • 0

I have 2 tables, a master table and a transaction table. I want to sort the
query result of the master table based on a condition : if a student number and studname is already
existing in the transaction table or basically, if the record (stud no, studname) is already in the
transaction table).

If the records is already exist, the result set should be in the last part of the query.

I’ve used to query here. I’ll just merge the 2 datasets or use a UNION

I have a query here but is doesn’t seem to work:

SELECT m.studno, m.studname FROM MASTERTABLE M 
inner JOIN TRANSACTTABLE S
ON m.STUDNO <> s.STUDNOO  and  m.studname <> s.studname

–this query is for the non existing records yet, and it should be on top of the query set.

SELECT m.studno, m.studname FROM MASTERTABLE M 
inner JOIN TRANSACTTABLE S
ON m.STUDNO = s.STUDNOO  and  m.studname = s.studname

–this query is for the existing records, and it should be on the lastrow of the query set.

Just a piece of illustration:

Let’s say MASTERTABLE CONTAINS

id, studno,    studname
9    78797     aaa
10  878         bbb
11  675         ccc
12  099         ddd

TRANSACTTABLE

id,     studno,    studname
13    878 bbb
14     675 ccc

Query result should be:

   studno, studname
    78797 aaa
    099 ddd
    878 bbb
    675 ccc

the first two row should consist of studname aaa and ddd since the two doesn’t
exist in the transact table, and the last two is bbb & ccc since it does
exist in the tranasct table.

How can I achieve this?

thanks. Please help

  • 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-25T15:53:41+00:00Added an answer on May 25, 2026 at 3:53 pm

    Try this:

    SELECT m.studno, m.studname
    FROM MASTERTABLE M
    LEFT JOIN TRANSACTTABLE S ON m.STUDNO = s.STUDNOO  and  m.studname = s.studname 
    ORDER BY s.STUDNO
    

    The NULL values in s.STUDNO will collect all the rows with no matches.

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

Sidebar

Related Questions

I have ten master tables and one Transaction table. In my transaction table (it
I have to tables, Table A is master, table B child. What is the
I've two master tables Org & Item and then there's an OrgItem table.I have
I have need to select a number of 'master' rows from a table, also
I have the following tables Master Table id ---- 1x 2x .... Assignment Table
I have two tables Master Detail In the Master & Detail table I get
I have two tables Master Detail In the Master & Detail table, i have
This is the case. I have a master table with an invoice number (int)
I have two tables as shown below The master Table ID keyword_tags ----------- ---------------------------------------------
i have an issue with query 1st table (Master) Name :MainCategory with fields (Category_id,Category_name)

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.