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

The Archive Base Latest Questions

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

here goes my two MySQL Queries and can some guide me which is the

  • 0

here goes my two MySQL Queries and can some guide me which is the best query to use as per MYSQl DATABase

the below goes my two sql queries

query 1)

 select cast(sum(G1.amount)as decimal(8,2)) as YTDRegularPay,cast(sum(b1.amount)as decimal(8,2))as YTDBonusPay 
 from tbl_employees_swc_grosswagedetails g1,tbl_employees_swc_grosswagedetails b1 
 where g1.empid=b1.empid 
 and g1.PayYear=b1.PayYear 
 and g1.PayperiodNumber=b1.PayperiodNumber  
 and g1.Fedtaxid=b1.Fedtaxid
 and g1.fedtaxid=998899889 
 and g1.payyear=2011 
 and g1.PayperiodNumber<=26 
 and g1.Wage_code='GRTT'
 and g1.Taxing_AuthType=b1.Taxing_AuthType 
 and g1.empid=1005 and b1.wage_code='GRSP' 
 and g1.taxing_AuthType='FED' ;

and
Query 2)

select abc.Amount as YTDRegularPay,def.Amount as YTDBonusPay
from (select Cast(sum(EG.Amount) as Decimal(8,2)) as Amount 
      from tbl_employees_swc_grosswagedetails EG 
      where EG.FedTaxID=998899889 
      and EG.EmpID=1005
      and PayYear=2011 
      and EG.PayPeriodNumber<=26 
      and EG.Wage_code='GRTT' 
      and Taxing_AuthType='FED') as abc,
(select Cast(sum(EG.Amount) as Decimal(8,2)) as Amount
from tbl_employees_swc_grosswagedetails EG 
where EG.FedTaxID=998899889 
and EG.EmpID=1005
and PayYear=2011 
and EG.PayPeriodNumber<=26 
and EG.Wage_code='GRSP'
and Taxing_AuthType='FED') as def ;

Here goes my Table structure

 delimiter $$

 CREATE TABLE `tbl_employees_swc_grosswagedetails` (

 `id` int(11) NOT NULL AUTO_INCREMENT,
`empid` int(11) NOT NULL,
`Fedtaxid` varchar(9) NOT NULL,
`Wage_code` varchar(45) NOT NULL,
 `Amount` double NOT NULL,
 `Hrly_Rate` double DEFAULT NULL,
`Num_hours` double DEFAULT NULL,
`Taxing_AuthType` varchar(10) DEFAULT NULL,
`Taxing_Auth_Name` varchar(10) DEFAULT NULL,
`PayperiodNumber` int(11) NOT NULL,
`PayYear` int(11) NOT NULL,
 PRIMARY KEY (`id`),
 KEY `empid` (`empid`),
 CONSTRAINT `empid` FOREIGN KEY (`empid`) REFERENCES `tblemployee` (`EmpID`) 
     ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=359 DEFAULT CHARSET=latin1$$

any good query else these are very much appreciable

Thanks IN adv,

Raghavendra.V

  • 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:50:55+00:00Added an answer on May 21, 2026 at 3:50 pm

    I would say the first one is better, since using JOIN is almost always better than using a subquery. It is also recommended to write the JOIN explicitly (though it does not matter in terms of performance), like this:

    SELECT 
        CAST(SUM(G1.amount) AS decimal(8,2)) AS YTDRegularPay,
        CAST(SUM(b1.amount) AS decimal(8,2)) AS YTDBonusPay
    FROM 
        tbl_employees_swc_grosswagedetails g1,
    JOIN 
        tbl_employees_swc_grosswagedetails b1 ON g1.empid = b1.empid
                                              AND g1.PayYear = b1.PayYear
                                              AND g1.PayperiodNumber = b1.PayperiodNumber
                                              AND g1.Taxing_AuthType = b1.Taxing_AuthType
                                              AND g1.Fedtaxid = b1.Fedtaxid
     WHERE 
         g1.fedtaxid = 998899889
         AND g1.payyear = 2011
         AND g1.PayperiodNumber <= 26
         AND g1.Wage_code = 'GRTT'
         AND b1.wage_code = 'GRSP'
         AND g1.empid = 1005
         AND g1.taxing_AuthType = 'FED';
    

    Adding some indexes will probably help as well to make both queries quicker. Since you use many columns in your WHERE clause, you need to choose which ones to index according to the data structure. Try adding a bunch of indexes, run the query with EXPLAIN and see which index is used – this one would be the most effective one and than you can drop the others.

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

Sidebar

Related Questions

I have two database tables, one in MYSQL and one in MSSQL. Both have
I have two boxes like: <div class=box> <div class=content>Here goes content 1.</div> </div> <div
It is possible that my question title is misleading, but here goes -- I
I apologise in advance for the poor quality of this question but here goes:
I am not entirely sure how to word this question, but here goes: I
I don't even know how to describe what I want, but here goes. Assume
Got a question for some of you rails guru's out there. I am developing
Hi I don't understand this simple SQL query with JOIN . I want to
See Edit 3 for latest developments: Backstory: I tried looking, and I hate to
I am breaking my head why the simplest thing is not working. All I

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.