Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

SQL Server JOINS Expand / Collapse
Author
Message
Posted Saturday, August 23, 2014 4:29 AM This worked for the OP Answer marked as solution
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:01 AM
Points: 2,533, Visits: 7,094
Quick analysis


First a simplified ERD
  +--------------+          +--------------+          +-----------------+ 
| Trial | | Culture | | CultureStep |
+--------------+ +--------------+ +-----------------+
| TrialID | ,---|-| CultureID |-|--, | CultureStepID |
| TrialCode | | | CultureName | '---|<| CultureID |
| CultureID |>|--' | (Culture ) | | ( CultureStep ) |
| (Trial ) | | (attributes) | | ( attributes ) |
| (attributes) | +--------------+ +-----------------+
+--------------+


Looking at the ERD, we can tell that:
Each Trial has one and only one Culture.
One or more Trials can share the same Culture.

And
Each Culture has one or more CultureSteps.
One or more Cultures can share one or more CultureSteps.


Inspecting the Cardinality
Table       | Row Count
------------|-----------
Trial | 6793
Culture | 2327
CultureStep | 13957



As the query "Select * from Culture inner join Trial on Culture.CultureID = Trial.CultureID" returns 6785 rows, we know that there are 8 (6793 - 6785) Trials sharing the same Culture. We can also tell that each Culture has the average of 6 CultureSteps (13957/2327 = 5.998).

Since we do not know the distribution of CultureID in the CultureStep table, the exact numbers cannot be produced but here is an approxymation:

Select * from (Culture inner join Trial on Culture.CultureID = Trial.CultureID) inner join CultureStep on Culture.CultureID=CultureStep.CultureID

Given that each CultureID appears aprox. 6 times in the CultureStep and the set Culture-Trial has 6785 entries, the expected result should have close to 6 x 6785 entries.

Post #1606608
Posted Monday, August 25, 2014 7:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 15, 2014 11:10 PM
Points: 18, Visits: 17
Thank you for the excellent post .

Can you please help me become capable of doing such analysis?

How were you able to make the simplified ERD and come up with the conclusions under it

I want to learn this and be good at it ...

Also , need to be good with joins and although I did read out several links with examples ...I still seem to find issues like when my brain cannot digest how an inner join would get more rows than the individual selects and so on.
Post #1607052
Posted Monday, August 25, 2014 7:25 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:01 AM
Points: 2,533, Visits: 7,094
shaimaa.tarekelshoeiby (8/25/2014)
Thank you for the excellent post .

Can you please help me become capable of doing such analysis?

How were you able to make the simplified ERD and come up with the conclusions under it

I want to learn this and be good at it ...

Also , need to be good with joins and although I did read out several links with examples ...I still seem to find issues like when my brain cannot digest how an inner join would get more rows than the individual selects and so on.

You are very welcome.
My suggestion is to grab a good book on the subject, i.e. "Database Modeling and Design" or "Data Modeling for the Business" and while reading through it, use only simple tools such as pen/paper or a text editor to work through exercises and examples. Also read up on the "Relational Database Theory", "Naive Set Theory" and "Relational Algebra". This should get you well on the way.

Another thing I find helpful, especially when tackling very complex problems, is to practice solving puzzles like Soduku by memory (not using pen and paper), keeps the grey matter functional
Post #1607063
Posted Monday, August 25, 2014 7:55 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 15, 2014 11:10 PM
Points: 18, Visits: 17
Thank you ...

But with so limited time , what can I do to help me go through until I can have more time to read the book(s) you suggested and use pen/paper?


Any recommended set of articles or a small daily exercise ; something of the sort? :)
Post #1607078
Posted Monday, August 25, 2014 8:00 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:22 AM
Points: 14,205, Visits: 28,534
There's no instant or magic way to build this kind of knowledge. It takes a long time. I'd add getting a copy of the book T-SQL Querying Fundamentals by Itzik Ben Gan. It's a great way to learn.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server Query Performance Tuning
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1607081
Posted Monday, August 25, 2014 8:00 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 15, 2014 11:10 PM
Points: 18, Visits: 17
Oh, an important question regarding the join

I learnt about using CTE instead of a view so that I can do it all as sql queries

However , adding the With part doesn't work with Access.

Is there anything that can be similarly done in Access (or should I be moving to a new thread?)

Thanks a lot in advance!
Post #1607082
Posted Monday, August 25, 2014 8:06 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 15, 2014 11:10 PM
Points: 18, Visits: 17
Alright thank you both...I should seriously consider
Post #1607083
Posted Monday, August 25, 2014 8:06 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 6:01 AM
Points: 2,533, Visits: 7,094
shaimaa.tarekelshoeiby (8/25/2014)
Oh, an important question regarding the join

I learnt about using CTE instead of a view so that I can do it all as sql queries

However , adding the With part doesn't work with Access.

Is there anything that can be similarly done in Access (or should I be moving to a new thread?)

Thanks a lot in advance!


I'm afraid that in Access you will have to stick with views.
Post #1607084
Posted Monday, August 25, 2014 8:16 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 8:22 AM
Points: 14,205, Visits: 28,534
Nope. Access doesn't use Transact SQL and the full T-SQL stack supported by SQL Server.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server Query Performance Tuning
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1607092
Posted Monday, August 25, 2014 8:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 15, 2014 11:10 PM
Points: 18, Visits: 17
The main problem which made me think of detaching from views is that update cannot be done (getting database exception : modification affects multiple base tables)
Post #1607099
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse