473,378 Members | 1,138 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.

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 1717
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******@autismuk.muralichucks.freeserve.co.uk> wrote in
message news:ck**********@newsg3.svr.pol.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
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...
16
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
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....
2
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...
3
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...
0
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...
1
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 =...
1
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...
2
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...
7
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...
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
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: 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...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.