So I have an Access database that I'm trying to build and was wondering was there a way that if I type in an ID into one table that it can populate values in the adjacent column from another table.
For example I have table_1 that has columns User ID and User Number.
And now that I'm creating table_2 I want when I enter the User Number that it populates the value for another column which will be User ID, sort of how a vlookup would work in excel.
I already built a relationship for the User Number column in table_2 so when I type in the value its pulling from table_1. But I can't get column User ID to populate with the corresponding value. Thanks
You don't need to build a second table that duplicates the data. Since you already have it in table 1 you can always refer to that relationship when querying data and should do so in order to avoid discrepancies between the two tables. In this instance if you want to return the user id from table 1 when you specify a user number you should just create a new query using the sql code:
SELECT table_1.[User Number], table_1.[User ID]
FROM table_1
WHERE table_1.[User Number] IN (12345, 12346, 12347);
In this example, the 12345, 12346, 12347 represent your user numbers for which ID's you were wanting to return; so you should only replace those values with your search parameters.
Related
I have two tables:
documents table
audits table.
audits table is a polymorphic table and has auditable_type and auditable_id which is linked to the id of documents table. audits table also has event and new_values column.
Here's the table schema.
documents table has user_defined_field JSON column.
My goal is I want to get the first 4 values of the status field in user_defined_field JSON column. There will be a column in the report of the web app to display the 1st Status, 2nd Status, 3rd Status, 4th Status.
So basically, it's like the documents table is join to audits table and should get the first 4 record of the document id and display it in the SQL select as status_1, status_2, status_3, and status_4
Thank you.
I have created a new trigger with table name as advance_audit, and I have a employee table, whenever user updates more than one column in employee form, I want to store those values in advance_audit table in old_value column. If user edits two records then two records should save in old_Value column,
At present only firstname is saving, i want to store other fields also like lastname. How to do it
Below is my code.
Insert into advance_audit
set action='update'
old_value =old.firstname
Thanks in advance
I am trying to create a View using certain fields from a single MYSQL table. But in one of the fields in the Table, I need to populate the field from either one field in the table or another field in the same table based on the value of a third field in the table. Is this possible, and if so, how?
To explain, The table contains data from two suppliers. The entries in the table from "Supplier A" store the Account Number in field CustomerNumber while the entries in the table from "Supplier B" store the Account Number in field CustomerAcct. The view I need to generate needs to list all of the customer orders from both suppliers combined, and populate a single field in the view called AccountNumber with either the value from CustoomerNumber or CustomerAcct, depending on which supplier filled the order.
Is this possible?
You'd use the "case" function, as in mysql case
CASE
WHEN Supplier = 'A' THEN customernumber
ELSE customeraccount
END as accountnumber
In my Users table I have a row called "products_in_sale" that contains the product ids of the products the user sells.
For one user it looks like this. "33" <-- therefore this very user sells only one product with the id 33.
Now, since users can sell more than one product, I have to join another number (preferably with a "," in between) to this field when a user creates a new product.
How does the necessary UPDATE statement have to look?
maybe 'UPDATE Users SET products_in_sale = products_in_sale + ", '.$id.'"'; ?
thanks for your help!
Use the CONCAT_WS function:
UPDATE Users SET products_in_sale = CONCAT_WS(',', products_in_sale, newProductId) where userId = ?
This query should work also for the first insert, if your products_in_sale column defaults to NULL.
Anyway, as suggested by juergen, using another table would be a better option.
Never never store multiple values in a single cell, this is a violation of first normal form (1NF). Read more: http://www.ntu.edu.sg/home/ehchua/programming/sql/Relational_Database_Design.html
Every value (e.g. product_id) should have its cell in a relational database table. In your case, there should be a table say "user_product" with at least 2 fields - "user_id" and "product_id", and both are composite primary key.
Of course, there should be a "user" table storing user details which would have a "user_id" field linking to the "user_id" field of the "user_product" table. Likewise, there should be a "product" table storing product details which would have a "product_id" field linking to the "product_id" field of the "user_product" table.
I need to append the data to a Access Table ULAE. I wants parameters to be picked from another table LAE.This table has 4 columns(Group,le,qtr,Table name) that will be an input and some parameters will be part of where condition. However there is one column table name that will have linked tables. Is it possible to pick the table name (that would be a linked table in the same access file, from where the data would be appended to ULAE).Is it possible to implement this in MSquery?
What i need is to pick the table name from LAE and append the data into ULAE from the table name specified in the LAE.
my query is like
INSERT INTO ULAE( vdate, profile_id, le, ibu)
SELECT PERSIAN.vdate, PERSIAN.profile_id, PERSIAN.le, PERSIAN.ibu
FROM **PERSIAN**;
**Persion is the linked table name coming from LAE**
Thanks in advance.