Relation on a multi-valued field in an Access database - database

Does someone know how I can put more than one value in one field to make a relation between two different records?
Google translation (from German):
Using multivalued fields
In most systems, DBMS (database management systems), including earlier
versions of Microsoft Access, you can only store a single value in a
field. In Microsoft Office Access 2007, you can also create fields
that contain multiple values​​, such as a list of categories to which
you have assigned a condition. Multivalued fields are used in specific
situations, such as when you use Office Access 2007 to work saved in a
Windows SharePoint Services 3.0 list that contains a field of one of
the field types with multiple values ​​that are available in Windows
data SharePoint Services.
This topic describes how to create and use multivalued fields in
Office Access 2007 and Windows SharePoint Services, how to create
multivalued fields and used, and how to use multivalued fields in a
query.

You can use multi-value Lookup fields in JOIN conditions (via their .Value property), but be aware that if there is such a field on both sides of the join then it will produce a match when any item matches on the joined fields, not when all items match. This may or may not be desirable, depending on the situation.
Case 1: Students with allergies
A school administrator needs to keep track of students with allergies and provide them with a list of meals that they should avoid when eating at the school cafeteria.
[Students]
ID Student Allergies
-- ------- ---------
1 Alice Eggs, Soy
2 Bradley Peanuts
3 Carol
4 Dennis Soy
[Meals]
ID Meal Allergens
-- ------------- ---------
1 Thai stir-fry Peanuts
2 Tofu omlette Eggs, Soy
3 Waffles Eggs
The query
SELECT Students.Student, Students.Allergies, Meals.Meal, Meals.Allergens
FROM Students INNER JOIN Meals ON Students.Allergies.Value = Meals.Allergens.Value;
returns
Student Allergies Meal Allergens
------- --------- ------------- ---------
Alice Eggs, Soy Tofu omlette Eggs, Soy
Alice Eggs, Soy Waffles Eggs
Bradley Peanuts Thai stir-fry Peanuts
Dennis Soy Tofu omlette Eggs, Soy
This is appropriate, since Alice should avoid meals that contain any ingredients to which she is allergic.
Case 2: Hotel requirements
[Travellers]
ID Traveller Requirements
-- --------- -------------------------
1 Gord free WiFi, in-room coffee
[Hotels]
ID Hotel Amenities
-- ------------ ----------------------------
1 Budget Motel free WiFi, in-room coffee
2 Fancy Hotel in-room coffee, room service
The query
SELECT Travellers.Traveller, Travellers.Requirements, Hotels.Hotel, Hotels.Amenities
FROM Hotels INNER JOIN Travellers ON Hotels.Amenities.Value = Travellers.Requirements.Value;
returns
Traveller Requirements Hotel Amenities
--------- ------------------------- ------------ ----------------------------
Gord free WiFi, in-room coffee Budget Motel free WiFi, in-room coffee
Gord free WiFi, in-room coffee Fancy Hotel in-room coffee, room service
The query returns both properties because they both offer in-room coffee. However, Fancy Hotel does not offer free WiFi, so I would prefer not to stay there. In this case the default join behaviour is not desirable (to me).

Related

Postgresql query to compare tables and find inside and outside results

I currently have a pair of datasets. They are closely related with each other in that they share a common column called product.
So the first table would look like this (provider table)
Provider
Product
John
Apples
John
Bananas
Steve
Apples
Steve
Pears
The second table would look like this (buyer table)
Buyer
Product
Elton
Apples
Elton
Kiwis
Austin
Bananas
Austin
Melons
The relationship that I need is on how the products that every provider has, relates to the products that every buyer also owns. Or in a simpler manner, what are the products a provider could sell to a buyer and which are the ones he is missing, with a focus on what are the products the buyer requires.
For instance, the relationship of the current users in the table would tell me
John -> Elton = Apples(Could Sell), Kiwis (Missing)
John -> Austin = Bananas(Could Sell), Melons (Missing)
Steve -> Elton = Apples(Could Sell), Kiwis (Missing)
Steve -> Austin = Bananas(Missing), Melons (Missing)
The idea is to end un with a table that looks like this, and that contains every provider, along with every relationship to every buyer, ordered first by providers, and then by buyers.
Provider
Buyer
Selling product
Missing Product
John
Elton
Apples
Kiwis
John
Austin
Bananas
Melons
Steve
Elton
Apples
Kiwis
Steve
Austin
----
Bananas, Melons
I have used this type of queries to try to find the products that match but it is not working as intended
from (
select tss.product , buyer_table.buyer
from buyer_table
inner join provider_table tss
on buyer_table.product = tss.product
group by tss.provider , buyer_table.buyer
) t join buyer_table c on t.buyer= c.buyer
order by t.provider desc;
Additionally, I have not being able to find a way of finding the products that do not match and have it grouped by Provider and Buyer.
It is ok to build this use case by parts, for instance find the products that match and dont match first, and then join them together, or do it all in a single query.
What are the SQL queries that I need in order to create this type of functionality?

The optimal way to enter multiple addresses for the same record within a form?

So I've been developing a sort of data entry platform within accessing using forms and subforms.
I have a form titled PHYSICIAN. Each physician will have basic data like first/last name, DOB, title, contract dates, etc. The aspect I'm wanting to cover is addresses as they may have multiple, since they may work/practice at 2 or 3 or even 10 different locations.
Instead of having our data entry team key in a full record each time they need to add an address, I'd like a way for the form to retain ALL information not related to the address.
So if Ken Bone works at 7 places, I want to allow them to key all of those addresses a bit more efficiently than creating a new record.
There's one main issue I'm running into --- A subform or autopopulate option doesn't necessarily increment the autonumber ID (primary key) for the record. All of the information is being stored in 1 master table.
Is there a way around this or a more logical approach that you folks might suggest?
I recommend that you have a couple of tables perhaps even three.
tblDoctorInfo
- Dr_ID
- Name
- DOB
- Title
tblAddresses
- AddressID
- Address1
- Address2
- City
- State
- Zip
- Country
tblDr_Sites
- DrSites_ID
- Dr_ID
- AddressID
The tables might have data like this.
tblDoctorInfo
1, Bob Smith, 12/3/1989, Owner
2, Carl Jones, 1/2/1977, CEO
3, Carla Smith, 5/3/1980, ER Surgeon
tblAddresses
1, 123 Elm St, Fridley, MN 55038
2, 234 7th St, Brookdale, MN 55412
3, 345 Parl Ave, Clinton, MN 55132
tblDr_Sites
Then you could associate the tables with the third table. (Note each of the three tables have an ID field that increments).
1,1,1 This record means Dr. Bob works in Fridley
2,1,2 This record means Dr. Bob works in Brookdale
3,3,1 This record means Dr. Carla works in Fridley
4,2,3 This record means Dr. Carl works in Clinton
5,2,2 This record means Dr. Carl works in Brookdale
6,2,1 This record means Dr. Carl works in Fridley

efficient Db Design with (many to many plus one to manys)

(revised) I have a web app where information will be entered for a user. First and last name as well as 3 Affiliations (primary, secondary, and tertiary) associated with the person. Each affiliation has 3 components (title, department, and university). So for example one record could be for:
User: Bob, Robertson
Affiliation1: Professor, Chemistry, U. Florida
Affiliation2: Director, Amazing Chemistry Institute, U. Florida
Affiliation3: Affiliated Faculty, BioChemistry, Florida Tech.
Also, Title and Department are text input fields but Univ. refers to a specific list of about 3000 university names 'univ_name' which is why it has it's own table. also affiliationOrdinal would be something like (1st, 2nd, 3rd)
Users Affiliation Univ.
======= ============ =========
id_user id_affiliation id_univ
FirstName id_user univ_name
LastName affiliationOrdinal
title
department
id_univ
Thanks Sean for your feedback, I started thinking of this more as a user with multiple addresess type of problem and that has been solved many times over it seems. I picked this one as a reference. Mysql database design for customer multiple addresses and default address. So the above should be a bit closer to workable right?

Designing a schedule in a sports database

I will try to be as specific as possible, but I am having trouble conceptualizing the problem. As a hobby I am trying to design a NFL database that takes raw statistics and stores it for future evaluation for fantasy league analysis. One of the primary things I want to see is if certain players/teams perform well against specific teams and which defenses are suspect to either pass/run. The issue I am having is trying to design the schedule/event table. My current model is as follows.
TEAMS
TeamID, Team
SCHEDULE
ScheduleID, TeamID, OpponentID, Season, Week, Home_Away, PointsFor, PointsAgainst
In this scenario I will be duplicating every game, but when I use an event table where I use TeamAway and TeamHome I find my queries impossible to run since I have to query both AwayTeam and HomeTeam to find the event for a specific team.
In general though I cannot get a query to work where I have two relationships from a table back to one table, even in the schedule table my query does not work.
I have also considered dropping the team table and just storing NE, PIT, etc. for the Team and Opponent fields so I do not have to deal with the cross-relationships back to the team table.
How can I design this so I am not running queries for TeamID = OpponentID AND TeamID?
I am doing this in MS Access.
Edit
The issue I am having is when I query two table: Team (TeamID, Team) and Event(TeamHomeID, TeamAwayID), that had relationships built between the TeamID - TeamHomeID, and TeamID - TeamWayID I had issues building the query in ms Access.
The SQL would look something like:
SELECT Teams.ID, Teams.Team, Event.HomeTeam
FROM Teams INNER JOIN (Event INNER JOIN Result ON Event.ID = Result.EventID)
ON (Teams.ID = Result.LosingTeamID) AND (Teams.ID = Result.WinningTeamID)
AND (Teams.Team = Event.AwayTeam) AND (Teams.Team = Event.HomeTeam);
It was looking for teams that had IDs of both the losing team and the winning team (which does not exist).
I think I might have fixed this problem. I didn't realize the Relationships in database design are only default, and that within the Query builder I could change the joins on which a particular query is built. I discovered this by deleting all the AND portions of the SQL statement returned, and was able to return the name of all winnings teams.
This is an interesting concept - and good practice.
First off - it sounds like you need to narrow down exactly what kind of data you want so you know what to store. I mean, hell, what about storing the weather conditions?
I would keep Team, but I would also add City (because Teams could switch cities).
I would keep Games (Schedule) with columns GameID, HomeTeamID, AwayTeamID, ScheduleDate.
I would have another table Results with columns ResultID, GameID, WinningTeamID, LosingTeamID, Draw (Y/N).
Data could look like
TeamID | TeamName | City
------------------------
1 | PATS | NE
------------------------
2 | PACKERS | GB
GameID | HomeTeamID | AwayTeamID | ScheduleDate | Preseason
-----------------------------------------------------------
1 | 1 | 2 | 1/1/2016 | N
ResultID | GameID | WinningTeamID | LosingTeamID | Draw
------------------------------------------------------------
1 | 1 | 1 | 2 | N
Given that, you could pretty easily give any W/L/D for any Scheduled Game and date, you could easily SUM a Teams wins, their wins when they were home, away, during preseason or regular season, their wins against a particular team, etc.
I guess if you wanted to get really technical you could even create a Season table that stores SeasonID, StartDate, EndDate. This would just make sure you were 100% able to tell what games were played in which season (between what dates) and from there you could infer weather statistics, whether or not a player was out during that time frame, etc.

How to scrape web pages that are in different format/layouts?

I need to scrape Form 10-K reports (i.e. annual reports of US companies) from SEC website for a project.
The trouble is, companies do not use the exact same format for filing this data. So for ex., real estate data for 2 different companies could be displayed as below
1st company
Property name State City Ownership Year Occupancy Total Area
------------- ----- ------ --------- ---- --------- ----------
ABC Mall TX Dallas Fee 2007 97% 1,347,377
XYZ Plaza CA Ontario Fee 2008 85% 2,252,117
2nd company
Property % Ownership %Occupany Rent Square Feet
--------------- ----------- --------- ----- -----------
New York City
ABC Plaza 100.0% 89.0% 38.07 2,249,000
123 Stores 100.0% 50.0% 18.00 1,547,000
Washington DC Office
12th street .......
2001, J Drive .......
etc.
Likewise, the data layout could be entirely different for other companies.
I would like to know if there are better ways to scrape this type of heterogenous data other than writing complex regex searches.
I have the liberty to use Java, Perl, Python or Groovy for this work.
I'd be inclined to keep a library of meta files that describe the layout for each page you want to scrape data from and use it when trying to get the data.
In that way you don't need complex reg-ex commands and if a site changes its design you simply change a single one of your files.
How you decide to create the meta file is up to you but things like pertinent class names or tags might be a good start.
then describe how to extract the data from that tag.
Unsure if there is a tool out there that does all that.
The other, nicer, way might be to contact the owners of these sites and see if they provide a feed in the form of a WebService or something that you can use to get the data. Saves a lot of heartache I should think.

Resources