Seem
Seem

Reputation: 271

Get values based on newly inserted value using SQL

I want to make filtration on a column after selecting a specific value of another column in the same table, I tried to use @... special character followed by the column's name to get the address of this value.

My SQL statement is like the following :

SELECT ATTRIBUTE FROM TABLE WHERE FIELD = '@FIELDNAME';

If I used a specific value instead of @FIELDNAME, it will work properly but it will be static but I need it to be dynamic based on the selected value.

Upvotes: 1

Views: 206

Answers (2)

IBRA
IBRA

Reputation: 1782

Create another table which will have the list of values that are in the FIELDNAME and give each record a unique id ,then retrieve the value depending on what you have selected by the name of the new table's field preceded by '@...'

I don't know if that what are you looking for, please let me know.

Upvotes: 1

bonCodigo
bonCodigo

Reputation: 14361

If no triggers are allowed, do you have any date/time column in the table? Is it possible to have that extra column anyway to see the time of a newly inserted row?

You may have to check the lastest row entered, save its field value into a variable. Then do the select based on the variable value.

Based on the vague last row id you could try the following (it's not pretty). But again, if you have date/time that's more accurate.

select attribute from table 
where field = (select field from table 
where rowid =(select max(rowid) from table))
;

upate Do you have the priviledge to set up your insert command as below:

insert into table (id, col1, col2,...) values (1,'something', 'something',...)
returning id into variable; -- you may either save field or id depending on your table

Then you may use this variable to select the records you want.

Upvotes: 0

Related Questions