Help! SQL select statement for an uncommon task

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jmaes Wang
    New Member
    • Oct 2010
    • 7

    Help! SQL select statement for an uncommon task

    Let’s say we have 3 tables: fruit name, color and taste that have data like this:

    Fruits:
    Apple

    Color:
    Red
    Green
    Yellow

    Taste:
    Sweet
    Bitter

    I need to come up with a single SQL statement that will combine all 3 tables so that for each fruit there will be as many records as max number of records in any of other tables (in this case 3 records because the Color table has 3 of them) and values will be in order how they appear in source tables like:

    Result of a statement I can’t come up with:
    Apple Red Sweet
    Apple Green Bitter
    Apple Yellow NULL
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    This is odd, in what situation would this be required?

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      I'm not sure why you need this, but a simple INNER JOIN will do...something like...

      Code:
      select fruit, color, taste
      from FruitTable f
      inner join ColorTable c where 1 = 1
      inner join TasteTable t where 1 = 1
      Happy Coding!!!

      ~~ CK

      Comment

      Working...