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. Fetch row and display in frontend column

Fetch row and display in frontend column

Scheduled Pinned Locked Moved Database
questiondatabase
4 Posts 4 Posters 5 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.
  • K Offline
    K Offline
    Kesiena
    wrote on last edited by
    #1

    I have 5 tables in my db, I used one form to saved into 4 of them at once. I want the 5th one to be used as a master where I can store the foreign key and be used to display to a table in the frontend. How do I make all of them add one ID? How can I display a table row as a column in the frontend?

    D J R 3 Replies Last reply
    0
    • K Kesiena

      I have 5 tables in my db, I used one form to saved into 4 of them at once. I want the 5th one to be used as a master where I can store the foreign key and be used to display to a table in the frontend. How do I make all of them add one ID? How can I display a table row as a column in the frontend?

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      Are you talking about fetching a column of data and displaying it as a single row? SQL Server has an interesting command that can do that. STRING_AGG (Transact-SQL) - SQL Server | Microsoft Learn[^]

      1 Reply Last reply
      0
      • K Kesiena

        I have 5 tables in my db, I used one form to saved into 4 of them at once. I want the 5th one to be used as a master where I can store the foreign key and be used to display to a table in the frontend. How do I make all of them add one ID? How can I display a table row as a column in the frontend?

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        How depends on the database. But typically an identity column. The table would have something like the following which is for SQL Server. Other databases all have something similar. Mongodb uses a 'object id' (typically.) {code} something_id INT IDENTITY(1,1) PRIMARY KEY, {code} That is how you create the column. But populating it in the other tables is more complicated. 1. You must first insert into the main table to create the id. 2. You must then get that id. That almost always involves using a specific form of the insert (first part) which returns the id at the same time as the insert occurs. 3. You then use that return value to create (insert) into the other tables. Obviously you will need to add a column to hold that new value. You can google for examples of using the above.

        1 Reply Last reply
        0
        • K Kesiena

          I have 5 tables in my db, I used one form to saved into 4 of them at once. I want the 5th one to be used as a master where I can store the foreign key and be used to display to a table in the frontend. How do I make all of them add one ID? How can I display a table row as a column in the frontend?

          R Offline
          R Offline
          Rohan Saadat
          wrote on last edited by
          #4

          It sounds like you have a scenario where you want to save data across multiple tables in a database using a single form. Additionally, you want to create a master table to store foreign keys and display the data in the frontend. Let's break down your requirements: 1. Generating a Common ID for Multiple Tables: When you want to add data to multiple tables at once and have them share a common identifier, you typically use a primary key (ID) that is common across all related tables. This can be achieved through database design and relationships. For example, let's say you have four tables: TableA, TableB, TableC, and TableD. Each of these tables has its own data, but they all share a common identifier, which could be a foreign key linking to a MasterTable. Here's a simplified example: CREATE TABLE MasterTable ( MasterID INT PRIMARY KEY, -- Other columns as needed ); CREATE TABLE TableA ( ID INT PRIMARY KEY, MasterID INT, -- Other columns for TableA FOREIGN KEY (MasterID) REFERENCES MasterTable(MasterID) ); -- Repeat the same structure for TableB, TableC, and TableD When you insert data into MasterTable, you generate a unique MasterID and use it as a foreign key in the other tables. This way, you can maintain relationships between the tables. 2. Displaying Table Rows as Columns in the Frontend: If you want to display data from a table row as columns in the frontend, you'll need to use SQL queries or your backend programming language to transform the data before sending it to the frontend. For example, suppose you have a table named Data: CREATE TABLE Data ( ID INT PRIMARY KEY, MasterID INT, ColumnName VARCHAR(50), ColumnValue VARCHAR(50), FOREIGN KEY (MasterID) REFERENCES MasterTable(MasterID) ); This table stores data in a key-value pair format, where each row represents a piece of data related to a MasterID. To display this data with columns dynamically created based on the ColumnName values, you can use a pivot query. Here's a simplified example in SQL: SELECT MasterID, MAX(CASE WHEN ColumnName = 'Column1' THEN ColumnValue END) AS Column1, MAX(CASE WHEN ColumnName = 'Column2' THEN ColumnValue END) AS Column2, -- Add more columns as needed FROM Data GROUP BY MasterID; This query transforms rows into columns based on the unique values in the ColumnName column. Keep in mind that the specifics of these solutions might depend on the exact requirements of your application, the database system you're usin

          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