Search Results

Search found 6276 results on 252 pages for 'join'.

Page 2/252 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • embedding LEFT OUTER JOIN within INNER JOIN

    - by user3424954
    I am having some problems with one of the question's answered in the book "SQL FOR MERE MORTALS". Here is the problem statement Here is the Database Structure Here is the answer which I am unable to comprehend Here is an answer which looks perfect to me Now the problem with the first answer I am having is: We first use LEFT OUTER JOIN for recipe class and recipes. So it selects all recipe class rows but only matching recipes. Perfecty fine as the question is demanding. Lets call this result set R. Now in the next step when we use INNER JOIN to join RecipieIngridients, it should filter out the rows from R in which Recipie ID doesn't match with the Recipe Id in Recipie Ingredients and hence filtering out the related Recipe class and recipe description also(Since it filters out the entire row of R). So this contradicts with the problem which demands all recipieID and RecipieDescription to be displayed from Recipe_Classes Table in this very step only. How can it be correct. Or Am i Missing some concept.

    Read the article

  • outer join for parent child chain

    - by dotnetcoder
    Considering below tables and relationships: parent --1:Many-- children --1:Many-- shubchildren Parent may or many not have children records. children always have subchildren records. I wan to write a qiery to select parent names where any if matched parent.name,children.name or subchildren.name Here i understand I have to do a left outer join between parent and children. But what kind of join should I put between children and subchildren ?

    Read the article

  • Basic join query understanding

    - by OM The Eternity
    I know this very silly, but can anybody help me in understanding what does this join query is doing in elabortive description? SELECT j1.* FROM jos_audittrail j1 LEFT OUTER JOIN jos_audittrail j2 ON (j1.trackid = j2.trackid AND j1.field = j2.field AND j1.changedone < j2.changedone) WHERE j1.operation = 'UPDATE' AND j1.trackid=$t_ids[$n] AND j2.id IS NULL I know its very silly, but i need to go ahead with my further need... Pls do help me...

    Read the article

  • MySQL Join Question

    - by rbaker86
    Hi i'm struggling to write a particular MySQL Join Query. I have a table containing product data, each product can belong to multiple categories. This m:m relationship is satisfied using a link table. For this particular query I wish to retrieve all products belonging to a given category, but with each product record, I also want to return the other categories that product belongs to. Ideally I would like to achieve this using an Inner Join on the categories table, rather than performing an additional query for each product record, which would be quite inefficient. My simplifed schema is designed roughly as follows: products table: product_id, name, title, description, is_active, date_added, publish_date, etc.... categories table: category_id, name, title, description, etc... product_category table: product_id, category_id I have written the following query, which allows me to retrieve all the products belonging to the specified category_id. However, i'm really struggling to work out how to retrieve the other categories a product belongs to. SELECT p.product_id, p.name, p.title, p.description FROM prod_products AS p LEFT JOIN prod_product_category AS pc ON pc.product_id = p.product_id WHERE pc.category_id = $category_id AND UNIX_TIMESTAMP(p.publish_date) < UNIX_TIMESTAMP() AND p.is_active = 1 ORDER BY p.name ASC I'd be happy just retrieving the category id's releated to each returned product row, as I will have all category data stored in an object, and my application code can take care of the rest. Many thanks, Richard

    Read the article

  • Nhibernate Left Outer Join Return First Record of the Join

    - by Touch
    I have the following mappings of which Im trying to bring back 0 - 1 Media Id associated with a Product using a left join (I havnt included my attempt as it confuses the situation) ICriteria productCriteria = Session.CreateCriteria(typeof(Product)); productCriteria .CreateAlias("ProductCategories", "pc", JoinType.InnerJoin) .CreateAlias("pc.ParentCategory", "category") .CreateAlias("category.ParentCategory", "group") .Add(Restrictions.Eq("group.Id", 333)) .SetProjection( Projections.Distinct( Projections.ProjectionList() .Add(Projections.Alias(Projections.Property("Id"), "Id")) .Add(Projections.Alias(Projections.Property("Title"), "Title")) .Add(Projections.Alias(Projections.Property("Price"), "Price")) .Add(Projections.Alias(Projections.Property("media.Id"), "SearchResultMediaId")) // I NEED THIS ) ) .SetResultTransformer(Transformers.AliasToBean<Product>()); IList<Product> products = productCriteria .SetFirstResult(0) .SetMaxResults(10) .List<Product>(); I need the query to populate the SearchResultMediaId with Media.Id, I only want to bring back the first Media in a left outer join, as this is 1 to many association between Product and Media Product is mapped to Media in the following way mapping.HasManyToMany<Media>(x => x.Medias) .Table("ProductMedias") .ParentKeyColumn("ProductId") .ChildKeyColumn("MediaId") .Cascade.AllDeleteOrphan() .LazyLoad() .AsBag(); Any Help would be fantastic.

    Read the article

  • LINQ, Left Join, Only Get where null in join table

    - by kmehta
    Hi. I am trying to do a left outer join on two tables, but I only want to return the results from the first table where the second table does not have a record (null). var agencies = from a in agencyList join aa in joinTable on a.AgencyId equals aa.AgencyId into joined from aa in joined.DefaultIfEmpty() where aa == null) select a; But this does not exclude the non null values of aa, and returns all the records just the same as if the 'where aa == null' was not there. Any help is appreciated. Thanks.

    Read the article

  • SQL: Join Parent - Child tables

    - by pray4Mojo
    I'm building a simple review website application and need some help with SQL Query. There are 3 tables (Topics, Comments, Users). I need a SQL query to select the data from all 3 tables. The 'Topics' table is the parent and the 'Comments' table contains the child records (anywhere from zero to 100 records per parent. The third table 'Users' contains the user information for all users. Here are the fields for the 3 tables: Topics (topicID, strTopic, userID) Comments (commentID, topicID, strComment, userID) Users (userID, userName) I tried: SELECT * FROM Topics Inner Join Comments ON Topics.topicID = Comments.topicID Inner Join Users ON Topics.userID = Users.userID But this does not work correctly because there are multiple topics and the User info is not joined to the Comments table. Any help would be appreciated.

    Read the article

  • Unable to log in to ubuntu server 10.04 after trying to join windows domain

    - by nash
    I was trying to join our ubuntu 10.04 server to the windows domain and I ended up editing the pam.d configuration files. My aim was to have domain users log into the ubuntu server with their domain accounts in order to access some applications instead of creating new unix users each time. My system admin says the join was successful to the domain. Now I have no way of logging into the sever. Is there a way I can undo everything and get the server back to the original login using the local account? I will also appreciate if someone pointed me to some configuration that actually worked - I am still willing to try and make it work.

    Read the article

  • How to JOIN a COUNT from a table, and then effect that COUNT with another JOIN

    - by jakenoble
    Hi I have three tables Post ID Name 1 'Something' 2 'Something else' 3 'One more' Comment ID PostId ProfileID Comment 1 1 1 'Hi my name is' 2 2 2 'I like cakes' 3 3 3 'I hate cakes' Profile ID Approved 1 1 2 0 3 1 I want to count the comments for a post where the profile for the comment is approved I can select the data from Post and then join a count from Comment fine. But this count should be dependent on if the Profile is approved or not. The results I am expecting is CommentCount PostId Count 1 1 2 0 3 1 Thanks for any help.

    Read the article

  • SQL Join query help

    - by lostInTransit
    Hi I have 2 tables A and B with the following columns Table A - id,bId,aName,aVal Table B - id,bName where A.bId is the same as B.id. I want a result set from a query to get A.id, A.aName, B.bName where A.bId=B.id OR A.id, A.aName, "" when A.bId=0. In both cases, only those records should be considered where A.aVal LIKE "aVal" Can someone please help me with the query? I can use left join but how do I get the blank string if bId=0 and B.bName otherwise? Thanks

    Read the article

  • Join using combined conditions on one join table

    - by Nathan Wienert
    I have join a table joining songs to genres. The table has a 'source' column that's used to identify where the genre was found. Genres are found from blogs, artists, tags, and posts. So, songs | song_genre | genres id | song_id, source, genre_id | id What I want to build is a song SELECT query that works something like this, given I already have a genre_id: IF exists song_genre with source='artist' AND a song_genre with source='blog' OR exists song_genre with source='artist' AND a song_genre with source='post' OR exists song_genre with source='tag' I'm was going to do it by doing a bunch of joins, but am sure I'm not doing it very well. Using Postgres 9.1.

    Read the article

  • MS SQL 2008, join or no join?

    - by Patrick
    Just a small question regarding joins. I have a table with around 30 fields and i was thinking about making a second table to store 10 of those fields. Then i would just join them in with the main data. The 10 fields that i was planning to store in a second table does not get queried directly, it's just some settings for the data in the first table. Something like: Table 1 Id Data1 Data2 Data3 etc ... Table 2 Id (same id as table one) Settings1 Settings2 Settings3 Is this a bad solution? Should i just use 1 table? How much performance inpact does it have? All entries in table 1 would also then have an entry in table 2. Small update is in order. Most of the Data fields are of the type varchar and 2 of them are of the type text. How is indexing treated? My plan is to index 2 data fields, email (varchar 50) and author (varchar 20). And yes, all records in Table 1 will have a record in Table 2. Most of the settings fields are of the bit type, around 80%. The rest is a mix between int and varchar. The varchars can be null.

    Read the article

  • SQL Server 2008, join or no join?

    - by Patrick
    Just a small question regarding joins. I have a table with around 30 fields and i was thinking about making a second table to store 10 of those fields. Then i would just join them in with the main data. The 10 fields that i was planning to store in a second table does not get queried directly, it's just some settings for the data in the first table. Something like: Table 1 Id Data1 Data2 Data3 etc ... Table 2 Id (same id as table one) Settings1 Settings2 Settings3 Is this a bad solution? Should i just use 1 table? How much performance inpact does it have? All entries in table 1 would also then have an entry in table 2. Small update is in order. Most of the Data fields are of the type varchar and 2 of them are of the type text. How is indexing treated? My plan is to index 2 data fields, email (varchar 50) and author (varchar 20). And yes, all records in Table 1 will have a record in Table 2. Most of the settings fields are of the bit type, around 80%. The rest is a mix between int and varchar. The varchars can be null.

    Read the article

  • Basics of Join Factorization

    - by Hong Su
    We continue our series on optimizer transformations with a post that describes the Join Factorization transformation. The Join Factorization transformation was introduced in Oracle 11g Release 2 and applies to UNION ALL queries. Union all queries are commonly used in database applications, especially in data integration applications. In many scenarios the branches in a UNION All query share a common processing, i.e, refer to the same tables. In the current Oracle execution strategy, each branch of a UNION ALL query is evaluated independently, which leads to repetitive processing, including data access and join. The join factorization transformation offers an opportunity to share the common computations across the UNION ALL branches. Currently, join factorization only factorizes common references to base tables only, i.e, not views. Consider a simple example of query Q1. Q1:    select t1.c1, t2.c2    from t1, t2, t3    where t1.c1 = t2.c1 and t1.c1 > 1 and t2.c2 = 2 and t2.c2 = t3.c2   union all    select t1.c1, t2.c2    from t1, t2, t4    where t1.c1 = t2.c1 and t1.c1 > 1 and t2.c3 = t4.c3; Table t1 appears in both the branches. As does the filter predicates on t1 (t1.c1 > 1) and the join predicates involving t1 (t1.c1 = t2.c1). Nevertheless, without any transformation, the scan (and the filtering) on t1 has to be done twice, once per branch. Such a query may benefit from join factorization which can transform Q1 into Q2 as follows: Q2:    select t1.c1, VW_JF_1.item_2    from t1, (select t2.c1 item_1, t2.c2 item_2                   from t2, t3                    where t2.c2 = t3.c2 and t2.c2 = 2                                  union all                   select t2.c1 item_1, t2.c2 item_2                   from t2, t4                    where t2.c3 = t4.c3) VW_JF_1    where t1.c1 = VW_JF_1.item_1 and t1.c1 > 1; In Q2, t1 is "factorized" and thus the table scan and the filtering on t1 is done only once (it's shared). If t1 is large, then avoiding one extra scan of t1 can lead to a huge performance improvement. Another benefit of join factorization is that it can open up more join orders. Let's look at query Q3. Q3:    select *    from t5, (select t1.c1, t2.c2                  from t1, t2, t3                  where t1.c1 = t2.c1 and t1.c1 > 1 and t2.c2 = 2 and t2.c2 = t3.c2                 union all                  select t1.c1, t2.c2                  from t1, t2, t4                  where t1.c1 = t2.c1 and t1.c1 > 1 and t2.c3 = t4.c3) V;   where t5.c1 = V.c1 In Q3, view V is same as Q1. Before join factorization, t1, t2 and t3 must be joined first before they can be joined with t5. But if join factorization factorizes t1 from view V, t1 can then be joined with t5. This opens up new join orders. That being said, join factorization imposes certain join orders. For example, in Q2, t2 and t3 appear in the first branch of the UNION ALL query in view VW_JF_1. T2 must be joined with t3 before it can be joined with t1 which is outside of the VW_JF_1 view. The imposed join order may not necessarily be the best join order. For this reason, join factorization is performed under cost-based transformation framework; this means that we cost the plans with and without join factorization and choose the cheapest plan. Note that if the branches in UNION ALL have DISTINCT clauses, join factorization is not valid. For example, Q4 is NOT semantically equivalent to Q5.   Q4:     select distinct t1.*      from t1, t2      where t1.c1 = t2.c1  union all      select distinct t1.*      from t1, t2      where t1.c1 = t2.c1 Q5:    select distinct t1.*     from t1, (select t2.c1 item_1                   from t2                union all                   select t2.c1 item_1                  from t2) VW_JF_1     where t1.c1 = VW_JF_1.item_1 Q4 might return more rows than Q5. Q5's results are guaranteed to be duplicate free because of the DISTINCT key word at the top level while Q4's results might contain duplicates.   The examples given so far involve inner joins only. Join factorization is also supported in outer join, anti join and semi join. But only the right tables of outer join, anti join and semi joins can be factorized. It is not semantically correct to factorize the left table of outer join, anti join or semi join. For example, Q6 is NOT semantically equivalent to Q7. Q6:     select t1.c1, t2.c2    from t1, t2    where t1.c1 = t2.c1(+) and t2.c2 (+) = 2  union all    select t1.c1, t2.c2    from t1, t2      where t1.c1 = t2.c1(+) and t2.c2 (+) = 3 Q7:     select t1.c1, VW_JF_1.item_2    from t1, (select t2.c1 item_1, t2.c2 item_2                  from t2                  where t2.c2 = 2                union all                  select t2.c1 item_1, t2.c2 item_2                  from t2                                                                                                    where t2.c2 = 3) VW_JF_1       where t1.c1 = VW_JF_1.item_1(+)                                                                  However, the right side of an outer join can be factorized. For example, join factorization can transform Q8 to Q9 by factorizing t2, which is the right table of an outer join. Q8:    select t1.c2, t2.c2    from t1, t2      where t1.c1 = t2.c1 (+) and t1.c1 = 1 union all    select t1.c2, t2.c2    from t1, t2    where t1.c1 = t2.c1(+) and t1.c1 = 2 Q9:   select VW_JF_1.item_2, t2.c2   from t2,             (select t1.c1 item_1, t1.c2 item_2            from t1            where t1.c1 = 1           union all            select t1.c1 item_1, t1.c2 item_2            from t1            where t1.c1 = 2) VW_JF_1   where VW_JF_1.item_1 = t2.c1(+) All of the examples in this blog show factorizing a single table from two branches. This is just for ease of illustration. Join factorization can factorize multiple tables and from more than two UNION ALL branches.  SummaryJoin factorization is a cost-based transformation. It can factorize common computations from branches in a UNION ALL query which can lead to huge performance improvement. 

    Read the article

  • Performing Inner Join for Multiple Columns in the Same Table

    - by frankiefrank
    I have a scenario which I'm a bit stuck on. Let's say I have a survey about colors, and I have one table for the color data, and another for people's answers. tbColors color_code , color_name 1 , 'blue' 2 , 'green' 3 , 'yellow' 4 , 'red' tbAnswers answer_id , favorite_color , least_favorite_color , color_im_allergic_to 1 , 1 , 2 3 2 , 3 , 1 4 3 , 1 , 1 2 4 , 2 , 3 4 For display I want to write a SELECT that presents the answers table but using the color_name column from tbColors. I understand the "most stupid" way to do it naming tbColors three times in the FROM section, using a different alias for each column to replace. How would a non-stupid way look?

    Read the article

  • Hibernate: Perform criteria query with Sub-Select AND Left-Outer join?

    - by Markos Fragkakis
    Can I perform a Criteria query with Sub-Select AND Left-Outer join? For example, I have A 1-many B 1-many C. With Criteria.createAlias ("b", "b", Criteria.LEFT_JOIN) I can perform Left Outer join. With Criteria.setFetchMode ("b", org.hibernate.FetchMode.DEFAULT) I can perform Join with the default fetching strategy. I assume that having set @org.hibernate.annotations.FetchMode.SUBSELECT in both A.B and B.C is enough (is it?). Question 1: Why does org.hibernate.FetchMode not have SUBSELECT option, whereas the org.hibernate.annotations.FetchMode does? Question 2: Can I perform a Criteria query with Sub-Select AND Left-Outer join?

    Read the article

  • Can MySQL / SQL's short hand of "Using" be used without saying "Inner Join" ?

    - by Jian Lin
    The following 2 statements are to join using gifts.giftID = sentgifts.giftID: mysql> select * from gifts, sentgifts using (giftID); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'using (giftID)' at line 1 and the second one: mysql> select * from gifts INNER JOIN sentgifts using (giftID); +--------+------------+----------------+---------------------+--------+------------+--------+------+---------------------+ | giftID | name | filename | effectiveTime | sentID | whenSent | fromID | toID | trytryWhen | +--------+------------+----------------+---------------------+--------+------------+--------+------+---------------------+ | 2 | teddy bear | bear.jpg | 2010-04-24 04:36:03 | 4 | 2010-04-24 | NULL | 111 | 2010-04-24 03:10:42 | | 6 | beer | beer_glass.png | 2010-04-24 05:18:12 | 5 | 2010-03-03 | 11 | 22 | 2010-03-03 00:00:00 | | 6 | beer | beer_glass.png | 2010-04-24 05:18:12 | 6 | 2010-04-24 | 11 | 222 | 2010-04-24 03:54:49 | | 6 | beer | beer_glass.png | 2010-04-24 05:18:12 | 7 | 2010-04-24 | 1 | 2 | 2010-04-24 03:58:45 | +--------+------------+----------------+---------------------+--------+------------+--------+------+---------------------+ 4 rows in set (0.00 sec) Can the first statement also use the "using" shorthand? It seems that when it is used then the word "Inner Join" must be specified... but the first statement is actually an inner join?

    Read the article

  • INNER JOIN vs LEFT JOIN performance in SQL Server

    - by Ekkapop
    I've created SQL command that use INNER JOIN for 9 tables, anyway this command take a very long time (more than five minutes). So my folk suggest me to change INNER JOIN to LEFT JOIN because the performance of LEFT JOIN is better, at first time its despite what I know. After I changed, the speed of query is significantly improve. I want to know why LEFT JOIN is faster than INNER JOIN? My SQL command look like below: SELECT * FROM A INNER JOIN B ON ... INNER JOIN C ON ... INNER JOIN D and so no

    Read the article

  • How sql server evaluates the multiple different joins?

    - by ziang
    Hi, i have a general question about how sql server evaluates the joins.The query is SELECT * FROM TableA INNER JOIN TableB ON TableB.id = TableA.id LEFT JOIN TABLEC ON TABLEC.id = TABLEB.id Q1: What tables is the left join based on? I know it will based on the TABLEC but what is the other one? Is it the result of the first inner join or the TABLEB specified in the left join condition? Q2: Is "LEFT JOIN TABLEC ON TABLEC.id = TABLEB.id" equivalent to "LEFT JOIN TABLEC ON TABLEB.id = TABLEC.id" Q3: Is the query equivalent to the following one? (with TABLEB.id replaced by TABLEA.id?) SELECT * FROM TableA INNER JOIN TableB ON TableB.id = TableA.id LEFT JOIN TABLEC ON TABLEC.id = TABLEA.id Thank you!

    Read the article

  • 3 SQL Join Concepts to Help You Choose the Right Join

    What do SQL joins and the "teach a man to fish" Chinese proverb have in common? SQL joins, like regular expressions, are one of those commonplace programming tasks in which true success is entirely dependent upon your ability to conceptualize the outcome. Fail to do so and you'll likely wind up spending a few hours in a frustrating round of trial and error. Like regular expressions, the proliferation of online examples has actually contributed to the frustration, providing the equivalent of a day's worth of fish rather than the proverbial fishing pool. The Future of SQL Server MonitoringMonitor wherever, whenever with Red Gate's SQL Monitor. See it live in action now.

    Read the article

  • Duplicate Items Using Join in NHibernate Map

    - by Colin Bowern
    I am trying to retrieve the individual detail rows without having to create an object for the parent. I have a map which joins a parent table with the detail to achieve this: Table("UdfTemplate"); Id(x => x.Id, "Template_Id"); Map(x => x.FieldCode, "Field_Code"); Map(x => x.ClientId, "Client_Id"); Join("UdfFields", join => { join.KeyColumn("Template_Id"); join.Map(x => x.Name, "COLUMN_NAME"); join.Map(x => x.Label, "DISPLAY_NAME"); join.Map(x => x.IsRequired, "MANDATORY_FLAG") .CustomType<YesNoType>(); join.Map(x => x.MaxLength, "DATA_LENGTH"); join.Map(x => x.Scale, "DATA_SCALE"); join.Map(x => x.Precision, "DATA_PRECISION"); join.Map(x => x.MinValue, "MIN_VALUE"); join.Map(x => x.MaxValue, "MAX_VALUE"); }); When I run the query in NH using: Session.CreateCriteria(typeof(UserDefinedField)) .Add(Restrictions.Eq("FieldCode", code)).List<UserDefinedField>(); I get back the first row three times as opposed to the three individual rows it should return. Looking at the SQL trace in NH Profiler the query appears to be correct. The problem feels like it is in the mapping but I am unsure how to troubleshoot that process. I am about to turn on logging to see what I can find but I thought I would post here in case someone with experience mapping joins knows where I am going wrong.

    Read the article

  • Would shell command join cause out of memory?

    - by Hancy
    I have two file to join. FILE 1: a A1 a A2 a A3 ... c C1 c C2 ... FILE 2: a feature1_of_a a feature2_of_a ... a featureN_of_a ... ... c feature1_of_c c feature2_of_c ... after join, i could get File like this: A1 feature1_of_a A2 feature1_of_a A3 feature1_of_a A1 feature2_of_a A2 feature2_of_a A3 feature2_of_a ... A1 featureN_of_a A2 featureN_of_a A3 featureN_of_a ... In order to do that: i wrote shell command join -11 -21 -o1.2,2.2 file1 file2. But the problem is: number N might be huge. So if join read all feautre of a into memory at once, memory might not be enough. I don't know how join is implemented. WQould the momery become a problem? If so, is there any way to get what I want?

    Read the article

  • SQL SERVER – Challenge – Puzzle – Why does RIGHT JOIN Exists

    - by pinaldave
    I had interesting conversation with the attendees of the my SQL Server Performance Tuning course. I was asked if LEFT JOIN can do the same task as RIGHT JOIN by reserving the order of the tables in join, why does RIGHT JOIN exists? The definitions are as following: Left Join – select all the records from the LEFT table and then pick up any matching records from the RIGHT table   Right Join – select all the records from the RIGHT table and then pick up any matching records from the LEFT table Most of us read from LEFT to RIGHT so we are using LEFT join. Do you have any explaination why RIGHT JOIN exists or can you come up with example, where RIGHT JOIN is absolutely required and the task can not be achieved with LEFT JOIN. Other Puzzles: SQL SERVER – Puzzle – Challenge – Error While Converting Money to Decimal SQL SERVER – Challenge – Puzzle – Usage of FAST Hint Reference: Pinal Dave (http://blog.sqlauthority.com) Filed under: Pinal Dave, SQL, SQL Authority, SQL Puzzle, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >