473,802 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting Rows

Hi there,

I have an admin system (Add/Modify/Delete) for two types of records in the
database. They have a Parent - Child relationship

My problem is that I want to display on the "parent" record whether the
child exists or not .

The records are found in two different tables, but have the same Primary
Key.

Any ideas

cheers

Steven
Jul 17 '05 #1
3 1737
Steven wrote:
I have an admin system (Add/Modify/Delete) for two types of records in the
database. They have a Parent - Child relationship

My problem is that I want to display on the "parent" record whether the
child exists or not .

The records are found in two different tables, but have the same Primary
Key.


You'll be wanting to use a LEFT JOIN then. With a left join you can show all
the results from the first table whether or not there is a related record
from the second/joined table. The columns that would have been displayed
from the second table will all be NULL.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #2
Steven wrote:
Hi there,

I have an admin system (Add/Modify/Delete) for two types of records in the
database. They have a Parent - Child relationship

My problem is that I want to display on the "parent" record whether the
child exists or not .

Left Join. If you select [stuff] from table 1 left join table 2 on [stuff]
then every record in table 1 will appear ; if there aren't child record(s)
in table 2 for table 1 then the corresponding field will be null.
The records are found in two different tables, but have the same Primary
Key.


I don't think you mean this :) they'll have different primary keys but a
foreign key in the child .
Jul 17 '05 #3

"Paul Robson" <au******@autis muk.muralichuck s.freeserve.co. uk> wrote in
message news:ck******** **@newsg3.svr.p ol.co.uk...
Steven wrote:
Hi there,

I have an admin system (Add/Modify/Delete) for two types of records in
the
database. They have a Parent - Child relationship

My problem is that I want to display on the "parent" record whether the
child exists or not .


Left Join. If you select [stuff] from table 1 left join table 2 on [stuff]
then every record in table 1 will appear ; if there aren't child record(s)
in table 2 for table 1 then the corresponding field will be null.
The records are found in two different tables, but have the same Primary
Key.


I don't think you mean this :) they'll have different primary keys but a
foreign key in the child .


It is possible for the primary key on the child table to be exactly the same
as the foreign key which links to the parent table. This is the way to
enforce a one-to-one relationship. If the child table has a different
primary key it will allow a one-to-many relationship which may not be
desirable.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #4

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

Similar topics

2
3849
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I could resolve with a simple function: Example: I have 50records - I want to update a selection of the recods - some,
16
1735
by: walexand | last post by:
I use the database mysql v.4. My problem is... I have a select like: select * from user where language = "de"; the result are then: id name =================== 1 max
3
3057
by: Viswanatha Thalakola | last post by:
Hello, Can someone point me to getting the total number of inserts and updates on a table over a period of time? I just want to measure the insert and update activity on the tables. Thanks. - Vish
2
1762
by: Adam | last post by:
In my MYISAM table I have an index (Index_A) on 2 fields (Field_A, Field_B). There are millions of rows in the table. The cardinality of Index_A is 53. I think a query to count the number of rows that match a pair of values for Field_A and Field_B should execute blindingly fast (in the index count the number of leaf nodes for the B-Tree node representing the indexed pair of values). My query looks like: SELECT count(*) FROM `table_A`...
3
2065
by: Peter | last post by:
Hi, This post is about counting rows and finding the max count in a group of rows. I'm trying to find the player who scored the most goals in a game. I know how to find out how many goals the players scored, but I do not know how to find the player who scored the most goals in a specific game. The tables:
0
1230
by: Chia Lee Lee | last post by:
Hello… I have problem when counting the number of records, which is based on the start date and end date. I have tried to use message box to prompt the result, but the result given is zero(0).Actually there have records in database which fulfill the “WHERE” clause condition in sql statement. Thanks for yours help… Carol, /* Below is my code sample(VB.NET) */ sDate = dtStart.Value.ToShortDateString eDate = dtEnd.Value.ToShortDateString
1
3061
by: Newmanbt | last post by:
I've got the following code testlabel.Text = allquestions.Select().Count.ToString(); GridView1.DataSource = allquestions.Select(); GridView1.DataBind(); testlabel.Text = GridView1.Rows.Count.ToString(); allquestions.Select().Count.ToString(); is reporting the correct value, but GridView1.Rows.Count.ToString(); is reporting the incorrect value (it is reporting 0)
1
1641
by: jasone | last post by:
hey, this is what ive got so far: ("SELECT (Select count(*) from tbl_flight_details) + (select count(*) FROM tbl_flight_departures) as grandtotal") i need to count all the records in the above 2 tables, following this query i need to count all the records depending on a certaion value... at the moment ive got them counting from just one table which is fine. rs6=cn.execute ("Select count(*) as cardiffdeparts from...
2
1614
by: akadeco | last post by:
Hi I need to write a script that will allow me to check the value of any link in a table cell. The desired result would be something like this: row.cell.innerHTML, allowing me to call the contents of the fourth cell in the first row. The following script may be of use as a starting point: <table id="table"> <tr> <td><a href="#">hello1</a></td> <td><a href="#">hello2</a></td>
7
6393
by: crochunter | last post by:
Hi I was trying to count rows and columns in a tab delimited flat file. Like here in example below i should be able to detect automatically the no of rows and columns. So I should get 5 columns and 6 rows. Something like that. one two three four five one two three four five one two three four five one two three four five one two three four five
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10536
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.