Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3951838
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:46:42+00:00 2026-05-20T01:46:42+00:00

I have three tables: Orders: orderid, valuedid, valuesdesc Customers: customerid, cutomdesc Groups: groupid, groupdesc

  • 0

I have three tables:

Orders:
orderid, valuedid, valuesdesc

Customers:
customerid, cutomdesc

Groups:
groupid, groupdesc

valueid – id of a customer or a group

valuesdesc – must filled with appropriate for inserted valueid description from Customers or Groups depend on what (customer or group) user selected in the client.

So, when client send an insert query for Orders it consists orderid for new order and valuedid. And on a client side I know what user selected: group or customer.

What I need: if a new row inserted in Orders, corresponding valuesdesc for valuedid from Customers or Groups inserted in valuesdesc column.

I have an idea to insert with new order record valuesdesc which would contain key – fake value to pick the right dictionary (customers or groups), but how to create that trigger I unfortunately don’t know for now.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T01:46:43+00:00Added an answer on May 20, 2026 at 1:46 am

    First, I must say this is a very uncommon design. When you are inserting a record into Orders, you use valuesdesc to hint at the table that valueid references. But as soon as valuesdesc gets filled by the trigger, valueid essentially loses any meaning. That is, you haven’t reveal us you’ve got any other way to tell a reference to Customers from a reference to Groups. So, you could just as well drop valueid altogether and use valuesdesc to pass both the ‘dictionary’ hint and the reference within that table.

    Other than that, because valueid can reference more than one table, you cannot use a foreign key constraint on it.

    Anyway, in your present design you could try this:

    CREATE TRIGGER Orders_UpdateValuesdesc
    ON Orders
    FOR INSERT
    AS
    UPDATE o
    SET valuesdesc = COALESCE(c.customdesc, g.groupdesc)
    FROM Orders o
      INNER JOIN inserted ON o.orderid = i.orderid
      LEFT JOIN Customers c ON i.valuesdesc = 'Customers'
        AND i.valueid = c.customerid
      LEFT JOIN Groups g ON i.valuesdesc = 'Groups'
        AND i.valueid = g.customerid
    

    The strings 'Customers' and 'Groups' are meant as the dictionary specifiers. You replace them with the actual values.

    The trigger uses LEFT JOIN to join both Customers and Groups, then fills Orders.valuesdesc with either customdesc or groupdesc, depending on which one is not null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have three tables, customers, orders and orderDetails. I'm doing this:
I have three tables Orders table and customers table and orderstatus table, both order
I have three tables, Products(ProductID, ProductName) Orders(OrderID, OrderDate) OrderDetails(ProductID, OrderID) Junction table between Products
I have three tables (individuals, groups & recordlabels) and want use the information between
I have three tables: order orderline (has orderID ) orderactions (has orderID ) Then
I have 2 tables: orders customers I need to get VIP customers- meaning customers
I have a requirement where there are 3 tables (Orders, details & users) OrderId
I have these three tables [ Orders, order_Items, order_comment ] | -Orders- | |
Alright, I'm trying to link three different tables (Customers, Orders, and Order Details), in
I have three tables in a mySQL databse as such: orders: order_sequence_number, contact_id, date_ordered

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.