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 6612293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:04:50+00:00 2026-05-25T20:04:50+00:00

I have a query which I want to have a default value from a

  • 0

I have a query which I want to have a default value from a table (you could call it a vlookup in excel). My query looks like this:

select stamdata_sd.id_sd AS id_sd, stamdata_sd.Type_sd
AS Type_sd from stamdata_sd;

I want the Type_sd field in the query to be a default value from a table called type_ty. Something like this:

select stamdata_sd.id_sd AS id_sd, stamdata_sd.Type_sd default(selected
from a table called type_ty, where the pk id_ty is the higest)
AS Type_sd from stamdata_sd;

So, when i make a new record in the query, the field Type_sd is auto filled with the newest instance in the type_ty table.

How am I able to write such a query?

  • 1 1 Answer
  • 0 Views
  • 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-25T20:04:50+00:00Added an answer on May 25, 2026 at 8:04 pm

    I think this is a really bad design. Your table will always have incorrect data in it. And it will always have some nulls in a column that should probably be NOT NULL.

    If I were you, I’d try writing a BEFORE INSERT and BEFORE UPDATE triggers to make sure the right data always goes into the base table. You can SELECT the current value from your type_ty table.

    The use of a BEFORE INSERT trigger is obvious. But you also want to make sure good data goes into that column should a user try to set it to NULL or to an empty string. So you need a BEFORE UPDATE trigger, too.

    There are also good ways to handle this in client code, after first fixing the data and constraints in the base table. Client code can require a value once a session, which it can use as the current value, or it can remember the last value used and insert it into the user interface (where it might be overtyped with a different value). You could store the current value in a cookie. Lots of ways.

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

Sidebar

Related Questions

I have a table, let's call it 'entries' that looks like this (simplified): id
I have a query which produces a list of orders like this: Invoice Description
I have a SELECT statement that looks like this: SELECT * FROM photos, p_votes
I have a MySQL query in which I want to include a list of
I have the following query which is working fine, but I also want to
I have a query which is meant to show me any rows in table
I have this query which works correctly in MySQL. More background on it here
I have a query which searches two separate fields in the same table... looking
I have a query which returns a series of cells of data from a
I have this query SELECT products_list.id_cat_unique, products_categories_list.*, COUNT(products_list.id_cat_unique) as counter FROM products_categories_ids LEFT JOIN

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.