473,378 Members | 1,469 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,378 software developers and data experts.

Count from detail table


Hi

I've two tables

TableA
id
name

TableB
id
tableA_id
desc
oper
As you can see tableA is a master and tableB is a detail table where
we can have many records for each related tableA record.

I need to get all records for tableA with a count on some oper of
tableB.

I suppose I can got it with a join or a subselect but I don't use SQL
often so I'm getting crazy with this stupid query...

Could somebody help ?

Thanks in advance

C

Feb 20 '08 #1
2 2287
It is a good practice to name related columns with the same name across
tables.

Here is a query that will give you the counts for selected oper:

SELECT A.id, A.name, COUNT(B.oper) AS oper_cnt
FROM TableA AS A
LEFT OUTER JOIN TableB AS B
ON A.id = B.tablea_id
AND B.oper = 'a'
GROUP BY A.id, A.name

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Feb 20 '08 #2
On 20 feb, 18:17, "Plamen Ratchev" <Pla...@SQLStudio.comwrote:
It is a good practice to name related columns with the same name across
tables.

Here is a query that will give you the counts for selected oper:

SELECT A.id, A.name, COUNT(B.oper) AS oper_cnt
FROM TableA AS A
LEFT OUTER JOIN TableB AS B
* ON A.id = B.tablea_id
*AND B.oper = 'a'
GROUP BY A.id, A.name

HTH,

Plamen Ratchevhttp://www.SQLStudio.com
Thank you !

C
Feb 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Cro | last post by:
Hello Access Developers, I'd like to know if it is possible to perform a count in an expression that defines a control source. My report is based on a query. In my report, I want a text box to...
2
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit...
4
by: Bo Peng | last post by:
Dear list, I am looking for a way to store a large amount of unique sequences that will be accessed by objects. The most important operations are: 1. Direct access to the sequences (from...
1
by: cpritcha | last post by:
I an new to access and trying to complete a summer camp evaluation form that counts the number of data that is the same. Let me explain about the table. I have a series of questions like...
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
0
by: Mike Wilson | last post by:
Dear group, I have an invoice entry form, which is a simple Master fields / Detail grid. The main summary information of the invoice are stored in one table in a dataset, which is bound using a...
2
by: John | last post by:
Hi I am trying to create a master/detail form. I have my master and details tables dragged onto the dataset. I have also dragged the fields from master table on the form which has created the...
14
by: zufie | last post by:
I have to create a QA report regarding callers calling into a phone hotline. The report consists of many checkboxes such as: Did the IBCCP agency contact you? Yes/NO How many days passed...
3
by: geraldjr30 | last post by:
hi, i have the following, which lists days of the week, and records associated with each of them from an MS Access table. i would like to know how to display the count of the records associated...
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.