473,385 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

self join or subselect

I have managed to do this report query. The good news is that it works but the returned query ignores all the other books which do not have sales or gift records for the previous months(10). What I need is for it to show records for all books in the table irrespective of previous month sales or gifted.Any help will be much appreciated

SELECT
sum(s1.bk_qty) AS csale,
sum(s2.bk_qty) AS lsale,
sum(g1.gQty) AS cgift,
sum(g2.gQty) AS lgift,
book.bk_Title,
book.bk_sellprice,
remark.remark,
SUM(stock.sto_qty) AS cstock,
book.bk_loc,
`language`.lan_name
FROM
sale AS s1 ,
sale AS s2 ,
gift AS g1 ,
gift AS g2 ,
book ,
remark ,
stock ,
`language`
WHERE
s1.s_year = '2010' AND
s1.s_month = '11' AND
s2.s_year = '2010' AND
s2.s_month = '10' AND
g1.gMonth = '11' AND
g2.gYear = '2010' AND
g1.gYear = '2010' AND
g2.gMonth = '10' AND
remark.r_year = '2010' AND
remark.r_month = '11'AND
book.bk_Id = s1.bk_id AND
book.bk_Id = s2.bk_id AND
book.bk_Id = remark.bk_Id AND
book.bk_Id=g1.bk_id AND
book.bk_Id=g2.bk_id AND
book.bk_Id=stock.bk_Id AND
book.bk_language=language.lan_id
GROUP BY
book.bk_Id,
s1.bk_id,
g1.bk_id,
remark.bk_Id,
g2.bk_id,
s2.bk_id,
stock.bk_Id
ORDER BY
book.bk_Id ASC
Dec 25 '10 #1
0 1281

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Denis St-Michel | last post by:
Hello All, Hope some Guru will be able to help me with this. Let's take this example table A ------------------------------------------------------------------------------- id | ...
1
by: Shmulik | last post by:
I have a table: MasterFileID FileName ParentID 1 Hello <null> 2 World 1 3 Another <null> 4 Again 1
2
by: Tech | last post by:
I have a table tblEmails where the columns are id,list_id,address_id. I have many lists. I need to find out if a couple of lists (list_ids - 1000,1001,1002) have same address_ids in common or...
6
by: Christopher Harrison | last post by:
Is there a way to store an indefinite number of keys in one field and self join them? Imagine, for example, you have a table of users with a "friends" column. Say user 1 is friends with users 9, 7,...
4
by: Shahzad | last post by:
dear respected gurus, I would like to knew how to apply append,insert query for a self table where no primary keys issues. i do have problem say there are 5 rows of single record, this is data...
6
by: davegb | last post by:
I'm trying to create a self-join table to show the relationship between employee and supervisor. In another thread, I was advised to create a SupervisorID in the employee table, a separate...
2
by: Ev | last post by:
I have a database table in SQL Server that has a self join. In C# I have a DataTable with a self-join. I have defined a foreign key constraint on the DataTable for the self join. The...
14
by: Jim Andersen | last post by:
I have a problem with this standard employee-supervisor scenario For pictures: http://www.databasedev.co.uk/self-join_query.html I want to show all employees "belonging" to a specific...
1
by: Tangz | last post by:
Hi all, I am trying to do a simple insert into query that inserts data from one table to itself. Here is the design of my table: Batch_Desc - Primary Key Item_Total Desc Subtotal
1
by: Paul H | last post by:
I have an Employees table with the following fields: EmployeeID SupervisorID Fred Bob Bob John Bob Mary Bill Bill I have created a self join in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.