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

How to total unique values from 2 tables

I am trying to tally up player appearances from two tables that contain sport game data.

Here are the columns:

Table 1: home_team

game_ID home, home_team, player1, player 2, player 3, player4

Table 2:visiting_team


game_ID home, home_team, player1, player 2, player 3, player4

The names under player1, player2 etc can be the same as a player in different games can play different positions.

I would like to find the unique player names in the two tables for each teams and figure out how many times they played and list it out like

Team A, name_of_player1, #apperances,
name_of_player2, #apperances, etc


How would I do it?
Attached Images
File Type: jpg soccer_db.jpg (74.3 KB, 331 views)
Sep 11 '10 #1
4 1479
liimra
119 100+
You have two options here but the correct one is to create a new table that stores players. Then you create report based on this table --> add another field and use the DCount function inside it (example
Expand|Select|Wrap|Line Numbers
  1. =DCount("PlayerOneFieldName","HomeTeamTable","[PlayerOneFieldName] = '" _
  2.     & Reports!ReportName!Player& "'")
If the same player moves from field to another (today is player 1, tomorrow player 2 and so on), you have to get the total of Counting all Fields where this player has played. Then it becomes like

Expand|Select|Wrap|Line Numbers
  1. NZ(DCount("PlayerOneFieldName","HomeTeamTable","[PlayerOneFieldName] = '" _
  2.     & Reports!ReportName!Player& "'"),0) + NZ(DCount("PlayerTwoFieldName","HomeTeamTable","[PlayerTwoFieldName] = '" _
  3.     & Reports!ReportName!Player& "'"),0) + .... 
.

The NZ will avoid errors if there are no records for this player.

Note that you better use this in the query of the report itself.

Hope this helps,

Regards,
Ali
Sep 11 '10 #2
Thanks for the solutions! How would I create a new table that extracts the unique player names?
Sep 12 '10 #3
liimra
119 100+
Just create a new table (name it PlayerTbl for example) and insert a new field (PlayerName).

Regards,
Ali
Sep 12 '10 #4
liimra
119 100+
Did you work it out?

Regards,
Ali
Sep 16 '10 #5

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

Similar topics

2
by: Ori | last post by:
Hi, I have two tables such that in each table I need to make sure that column x in table A and column y in table B have a unique values meaning that a user cannot insert a value to column A if...
0
by: web1110 | last post by:
Hi y'all, I was playing with the NorthWind database, displaying subtables in a DataGrid. It worked fine for 3 levels, but when I added a fourth, I got the following error: These columns...
2
by: Benjamin Smith | last post by:
I have two tables like following: create table attendancereport ( id serial unique not null, staff_id integer not null references staff(id), schoolyear varchar not null references...
8
by: nescio | last post by:
hello, i have an array and i don't know the content of it, but i want only unique values. in php there is a function to do this, but how must i do this in javascript? i have tried a lot and...
11
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation a table with columns and rows
1
by: yasmine | last post by:
Hi friends, Can anyone tell me how can i write a php script which extract all the unique values of a field from multiple tables? and also if anybody enters some new values it also should be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.