Hey.
i have a table that has the columns of A,B,C,D
and another table that one of the coulmns the VALUES of A,B,C,D
i am trying to subquery the 2nd table at the coulmn that stores the abcd.
and the result act as a column name for the 1st table.

Example :

SELECT (SELECT LetterType
        FROM table2
        WHERE ID=1 // JUST FOR THE EXAMPLE TO RETURN 1 ROW
        ) as ColumnName
FROM table1
WHERE ID=1 // same reason

the subquery can only return A\B\C\D which are the column names in table1.

can i do that? because it doesn't work and i don't know if i can even do that.
and if i can, do you know how can i achive this?

Thanks in advance,
Eric

Recommended Answers

Try inner join..


SELECT t2.LetterType
FROM table1 t1
inner join table2 t2
on t1.ID = t2.ID
WHERE t1.ID=1

Jump to Post

All 2 Replies

Try inner join..


SELECT t2.LetterType
FROM table1 t1
inner join table2 t2
on t1.ID = t2.ID
WHERE t1.ID=1

create #Temptable and store values from table2 and then store this values in table1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.