sql - Best practices for multiple table joins UNION vs JOIN -


i'm using query brings ~74 fields different database tables.

  • the query consists of 10 full joins , 15 left joins.
  • each join condition based on different fields.

the query fetches data main table contains 90% foreign keys. i'm using joins foreign keys of data doesn't require joins because it's type of data(as logic) doesn't use information.

let me give example: each employee can have multiple tasks.there 4 types of tasks(1,2,3,4). each tasktype has different meaning. when running query , i'm getting data tasktypes , logic showing them separately.

my question : better use union , split 4 different cases queries? way use required joins each case in each union.

thanks,

i think depends on size (row number count) of main table e.g. task tables.

say if main table has tens of millions of rows , tasks smaller, union tasks necessitate table scans every time, whereas join smaller task tables can 1 table scan.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -