A single query between two tables without link on its fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mariusseven
    New Member
    • Mar 2008
    • 19

    A single query between two tables without link on its fields

    SELECT
    SUM (fieldname) AS T_Withheld
    ,SUM (fieldname) AS G_Income

    ,SUM(fieldname) + SUM (fieldname) + SUM(fieldname) + SUM(fieldname) AS Premium
    ,SUM (fieldname) - fieldnameC - (SUM(fieldname) + SUM (fieldname) + SUM(fieldname) + SUM(fieldname)) AS T_Income
    ,fieldnameA
    ,fieldnameB

    FROM tablename A
    GROUP
    BY fieldnameA
    ,fieldnameB
    ,fieldnamec

    and


    select fieldnameA, fieldnameB, fieldnameC, fieldnameD

    from tablename B

    Really need ideas
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    By no link do you mean there is no common field between the two tables?
    If that is the case what is wrong with two select statements?

    Comment

    • poe
      New Member
      • Jun 2007
      • 32

      #3
      You don't have to have a link to join tables. There should be something similar between these two tables to join on, correct?

      I think it would help if you gave full, correct SQL statement(s).

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        How would you know which record pairs with what record?

        -- CK

        Comment

        • mariusseven
          New Member
          • Mar 2008
          • 19

          #5
          I want to make only one query because i'll be using it to create a .ttx file of crystal reports to be used in vb6.




          Originally posted by code green
          By no link do you mean there is no common field between the two tables?
          If that is the case what is wrong with two select statements?

          Comment

          • mariusseven
            New Member
            • Mar 2008
            • 19

            #6
            The data i need are from two tables that have nothing in common..is it impossible to create a single query on both of their fields?


            Originally posted by ck9663
            How would you know which record pairs with what record?

            -- CK

            Comment

            • ck9663
              Recognized Expert Specialist
              • Jun 2007
              • 2878

              #7
              Not impossible.

              Would you mind posting sample data on both tables an how you want it joined?

              -- CK

              Comment

              • mariusseven
                New Member
                • Mar 2008
                • 19

                #8
                Sorry for the late relpy..
                here is the sample of tables....

                table 1
                Name......Cont1 ..... Cont2...... Cont3.....Cont4

                Name1 .....100 ......200 .........300... ......400
                Name2......500. ..... 600..........70 0.........800
                Name3 ......900...... 1000........110 0 ......1200

                table 2
                Code ......%Cont ......ContA.... ..ContIN ..... ContFL
                Code1 ...... 0 .............. 0 ........ 0 ............ 100000
                Code2. ...... 5 ........... 500.........100 00........30000
                Code3. .......10...... .. ..1000........3 0000 ....... 70000
                Code4.........1 5...........150 0........70000 ...... .14000

                Comment

                • ck9663
                  Recognized Expert Specialist
                  • Jun 2007
                  • 2878

                  #9
                  How do you want this joined? How would the joined table look?

                  -- CK

                  Comment

                  • mariusseven
                    New Member
                    • Mar 2008
                    • 19

                    #10
                    i just want the query of both tables, i don't want them to join or merge. i want to query them using a single query with filters.
                    Its like i want to compare the total values of the first table cont to the range of the values of the second.


                    Originally posted by ck9663
                    How do you want this joined? How would the joined table look?

                    -- CK

                    Comment

                    • code green
                      Recognized Expert Top Contributor
                      • Mar 2007
                      • 1726

                      #11
                      just want the query of both tables, i don't want them to join or merge. i want to query them using a single query with filters
                      A JOIN doesn't merge tables,
                      it merges results from the tables in to one recordset.
                      The tables are unaffected.
                      You want to run a query collecting results from both tables which is normally a JOIN query,
                      but requires common data in at least one field of each table.
                      Without this you could try a UNION which is two SELECT statements with UNION between.
                      The number of fields in each SELECT must match

                      Comment

                      • ck9663
                        Recognized Expert Specialist
                        • Jun 2007
                        • 2878

                        #12
                        I'll give him the benefit of the doubt ;)

                        Based on your example, how would you do it in a pseudo-code?

                        -- CK

                        Comment

                        • mariusseven
                          New Member
                          • Mar 2008
                          • 19

                          #13
                          The code i have made was the one that i have posted first, but i have no idea on how to connect the two...


                          Originally posted by ck9663
                          I'll give him the benefit of the doubt ;)

                          Based on your example, how would you do it in a pseudo-code?

                          -- CK

                          Comment

                          • code green
                            Recognized Expert Top Contributor
                            • Mar 2007
                            • 1726

                            #14
                            We seem to be going around in circles.
                            The code i have made was the one that i have posted first, but i have no idea on how to connect the two
                            By connect I have to assume you mean JOIN.
                            Unfortunately YOU need to tell us how you want the tables JOINed because we do not know what you are trying to achieve.
                            Its like i want to compare the total values of the first table cont to the range of the values of the second
                            How are you hoping to do this?

                            Comment

                            Working...