Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 SQL Server JOINS Rate Topic Display Mode Topic Options
Author
 Message
 Posted Saturday, August 23, 2014 4:29 AM This worked for the OP
 SSCertifiable Group: General Forum Members Last Login: Today @ 2:57 AM Points: 6,574, Visits: 17,298
 Quick analysisFirst 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.AndEach Culture has one or more CultureSteps.One or more Cultures can share one or more CultureSteps.Inspecting the Cardinality`Table | Row Count------------|-----------Trial | 6793Culture | 2327CultureStep | 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.CultureIDGiven 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 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
 SSCertifiable Group: General Forum Members Last Login: Today @ 2:57 AM Points: 6,574, Visits: 17,298
 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 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
 SSCoach Group: General Forum Members Last Login: 2 days ago @ 12:29 PM Points: 17,173, Visits: 32,140
 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 RooseveltThe Scary DBAAuthor of: SQL Server Query Performance Tuning and SQL Server Execution PlansProduct Evangelist for Red Gate Software
Post #1607081
 Posted Monday, August 25, 2014 8:00 AM
 Grasshopper Group: General Forum Members Last Login: Monday, September 15, 2014 11:10 PM Points: 18, Visits: 17
 Oh, an important question regarding the joinI learnt about using CTE instead of a view so that I can do it all as sql queriesHowever , 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 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
 SSCertifiable Group: General Forum Members Last Login: Today @ 2:57 AM Points: 6,574, Visits: 17,298
 shaimaa.tarekelshoeiby (8/25/2014)Oh, an important question regarding the joinI learnt about using CTE instead of a view so that I can do it all as sql queriesHowever , 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
 SSCoach Group: General Forum Members Last Login: 2 days ago @ 12:29 PM Points: 17,173, Visits: 32,140
 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 RooseveltThe Scary DBAAuthor of: SQL Server Query Performance Tuning and SQL Server Execution PlansProduct Evangelist for Red Gate Software
Post #1607092
 Posted Monday, August 25, 2014 8:32 AM
 Grasshopper 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

 Permissions