Forum Replies Created

Viewing 14 posts - 16 through 29 (of 29 total)

  • RE: Finding the right JOIN type

    As you haven't posted the complete list of tables you have to work with and the full view of results you want to get (you've posted a simplified version), I've...

  • RE: Finding the right JOIN type

    ChrisM@Work (6/12/2012)


    Good grief, this thread reads like a traincrash.

    Maybe it does, but if you take a look at my join-based solution (which I've offered above), you'll see that it doesn't...

  • RE: Finding the right JOIN type

    And here's my version with use of pivot:

    select style,lbl,div

    from (

    select

    a.style,

    c.type_name,

    b.group_name

    from

    zzxstylr as a

    join zzxpgtyr as c

    on c.type_name='LBL'

    or c.type_name='DIV'

    /*or (on c.pkey=1 or c.pkey=8) if you like*/

    /*determine the group_type corresponding to the group_col1...

  • RE: Finding the right JOIN type

    vinu512 (6/11/2012)


    Any Logic could be applied to get an expected Result Set.

    By the way, if any logic could be applied, why wouldn't you suggest the simplest solution:select * from (values...

  • RE: Finding the right JOIN type

    vinu512 (6/11/2012)


    Any Logic could be applied to get an expected Result Set.

    But in your case there doesn't seem to be a fixed universal Logic.

    Without a clear logic there could be...

  • RE: Finding the right JOIN type

    Here's my old version that now has been renewed and that now uses aliases.

    By the way, pay attention to the comment where I suggest to compare not only group_type and...

  • RE: Finding the right JOIN type

    I'm not a pro in this area, but as I understand, «Min(Group_Name)» — isn't a the right rule that correctly determines which group corresponds to the style. As I understood, the...

  • RE: Finding the right JOIN type

    Check out my previous post, 'cause it seems that I've found a solution to your problem while you were correcting the mistypes 🙂

    UPD! 'Check out my previous post'S! My solution...

  • RE: Finding the right JOIN type

    This is the solution of your problem:

    Oops… 🙁 While editing this post I accidentally deleted all the text except sql-code. Though, it steel works.

    select

    zzxstylr.style,

    lbl_zzxpgrpr.group_name as lbl,

    div_zzxpgrpr.group_name as div

    from

    zzxstylr...

  • RE: Finding the right JOIN type

    And these are results i have when executing your query:

    It's only 3 lines here, not 8 like you wrote… Do I do something wrong?

  • RE: Finding the right JOIN type

    CREATE TABLE zzxstylr

    (division FK varchar(3),style varchar(12),group_code1 varchar(9),group_code2 varchar(9),group_code3 varchar(9),

    group_code4 varchar(9),group_code5 varchar(9),group_code6 varchar(9),group_code7 varchar(9),group_code8 varchar(9))

    INSERT INTO zzxstylr

    VALUES ('MDG','2204852','02', '', '', '', '', '', '', '01')

    CREATE TABLE zzxpgrpr

    (division varchar(3), group_type varchar(1),group_code varchar(9),group_name...

  • RE: Finding the right JOIN type

    The code you've posted contains mistypes (it doesn't work in ssms). It means you didn't tested your code yourself. Would you like us to post unworking code too? 🙂

  • RE: Finding the right JOIN type

    I completely agree with Sean and Lynn: post, please, DDL-code (the definitions of your tables (including foreign key constraints)) and DML-code (sample data) and the results you want to have.

    Moreover,...

  • RE: Finding the right JOIN type

    I'm not a professional in SQL, I'm a newbie.

    But I think I could help… As I understand, you have this:

    style_table:

    style | group_code1 | … | group_code8

    --------+-------------+---+-------------

    style1 |...

Viewing 14 posts - 16 through 29 (of 29 total)