Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. view in which each column contains data from a different table

view in which each column contains data from a different table

Scheduled Pinned Locked Moved Database
phpmysqlhelptutorialquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11806910
    wrote on last edited by
    #1

    I am doing a student attendance project in php & mysql. I have a monthly table for recording attendance of students. the first column in the table is the roll number which is common for all the tables and the dates of each month have a column of their own. suppose if the attendance is of 5 months, I have 5 tables of the same repeated table. I want to create a table or view that has columns for showing total of each month with the students roll number i.e. student roll number column, first month total column, second month total column, so on. Can anyone please help me how to do it in mysql?

    M 1 Reply Last reply
    0
    • U User 11806910

      I am doing a student attendance project in php & mysql. I have a monthly table for recording attendance of students. the first column in the table is the roll number which is common for all the tables and the dates of each month have a column of their own. suppose if the attendance is of 5 months, I have 5 tables of the same repeated table. I want to create a table or view that has columns for showing total of each month with the students roll number i.e. student roll number column, first month total column, second month total column, so on. Can anyone please help me how to do it in mysql?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Member 11840363 wrote:

      if the attendance is of 5 months, I have 5 tables of the same repeated table.

      Let me get this clear, every month you create a new table for attendances. In which case you should start again and design your data structure to be sustainable, that design is absolutely NOT. You need just 1 table StudentID (roll number) Date If you have a table for each month then whatever you create you are going to have to redo every month unless the tables are year independent IE tblJan, tblFeb etc. This is still a really bad design but can be worked with under duress. You can create a view using UNION and a select statement for each month table but you will need to add another select every month.

      Never underestimate the power of human stupidity RAH

      U CHill60C 2 Replies Last reply
      0
      • M Mycroft Holmes

        Member 11840363 wrote:

        if the attendance is of 5 months, I have 5 tables of the same repeated table.

        Let me get this clear, every month you create a new table for attendances. In which case you should start again and design your data structure to be sustainable, that design is absolutely NOT. You need just 1 table StudentID (roll number) Date If you have a table for each month then whatever you create you are going to have to redo every month unless the tables are year independent IE tblJan, tblFeb etc. This is still a really bad design but can be worked with under duress. You can create a view using UNION and a select statement for each month table but you will need to add another select every month.

        Never underestimate the power of human stupidity RAH

        U Offline
        U Offline
        User 11806910
        wrote on last edited by
        #3

        Thanks for taking out some time to reply to my query. I have tried Union and select statements but I am not getting the desired result. It would be of great help if you show me some snippet or syntax of the query for example joining 4 tables using union and select. For the tables creation part I was thinking about creating procedures to create a table whenever needed, and at the time of creation the name of the table to be created and the table it references should be asked. It would be great help if you could help with the above both.

        M J 2 Replies Last reply
        0
        • U User 11806910

          Thanks for taking out some time to reply to my query. I have tried Union and select statements but I am not getting the desired result. It would be of great help if you show me some snippet or syntax of the query for example joining 4 tables using union and select. For the tables creation part I was thinking about creating procedures to create a table whenever needed, and at the time of creation the name of the table to be created and the table it references should be asked. It would be great help if you could help with the above both.

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Member 11840363 wrote:

          For the tables creation part I was thinking about creating procedures to create a table

          NO! just don't go down this path, redesign you data to have only 1 table. Seriously you are making a HUGE mistake if you do not structure your data properly. If you are able to write procedures then I assume you own the database. Restructure NOW before you do any more work. You need 1 table with a min of 2 fields RollNo and date.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • M Mycroft Holmes

            Member 11840363 wrote:

            if the attendance is of 5 months, I have 5 tables of the same repeated table.

            Let me get this clear, every month you create a new table for attendances. In which case you should start again and design your data structure to be sustainable, that design is absolutely NOT. You need just 1 table StudentID (roll number) Date If you have a table for each month then whatever you create you are going to have to redo every month unless the tables are year independent IE tblJan, tblFeb etc. This is still a really bad design but can be worked with under duress. You can create a view using UNION and a select statement for each month table but you will need to add another select every month.

            Never underestimate the power of human stupidity RAH

            CHill60C Offline
            CHill60C Offline
            CHill60
            wrote on last edited by
            #5

            I wish I could up vote this from my phone! Spot on advice

            1 Reply Last reply
            0
            • U User 11806910

              Thanks for taking out some time to reply to my query. I have tried Union and select statements but I am not getting the desired result. It would be of great help if you show me some snippet or syntax of the query for example joining 4 tables using union and select. For the tables creation part I was thinking about creating procedures to create a table whenever needed, and at the time of creation the name of the table to be created and the table it references should be asked. It would be great help if you could help with the above both.

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #6

              Listen to the man, seriously, it's the best advice you'll ever get regarding databases.

              Wrong is evil and must be defeated. - Jeff Ello

              U 1 Reply Last reply
              0
              • J Jorgen Andersson

                Listen to the man, seriously, it's the best advice you'll ever get regarding databases.

                Wrong is evil and must be defeated. - Jeff Ello

                U Offline
                U Offline
                User 11806910
                wrote on last edited by
                #7

                Thanks a lot guys for your valuable time. I realize that it is a complicated design to manage and not that convenient either for maintaining. but can anyone help me the possible solutions that would help in such a scenario for knowledge purpose.

                L M 2 Replies Last reply
                0
                • U User 11806910

                  Thanks a lot guys for your valuable time. I realize that it is a complicated design to manage and not that convenient either for maintaining. but can anyone help me the possible solutions that would help in such a scenario for knowledge purpose.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  That's like asking how to build a car with the wheels on top for knowledge purposes. Normalize your tables, and querying becomes simpeler.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                  1 Reply Last reply
                  0
                  • U User 11806910

                    Thanks a lot guys for your valuable time. I realize that it is a complicated design to manage and not that convenient either for maintaining. but can anyone help me the possible solutions that would help in such a scenario for knowledge purpose.

                    M Offline
                    M Offline
                    Mycroft Holmes
                    wrote on last edited by
                    #9

                    Don't you get the impression you may have done something incorrectly, the only response you have had is to fix your data structure. As Eddy said once yo have done that the query becomes trivial. It is possible to hack around the terrible structure you have built but us showing you for any reason is doing you a disservice. We are here to help you learn, help fix problems, we are not interested in perpetrating bad design.

                    Never underestimate the power of human stupidity RAH

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups