Click here to Skip to main content
15,905,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created two table Test, Test1. I want to read the data from it but it will give an error, Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.


My query,
SQL
SELECT mono,
        Fax,
        (SELECT Color, Test
            FROM Test1),
        Name,
        Birthdate
        FROM Test;
Posted
Comments
Suvendu Shekhar Giri 6-Jan-15 1:06am    
You can't specify more than one column in a sub query.
Problem is here
SELECT Color, Test FROM Test1
In this case, you also need to make sure it returns only a single row of data. May be you are missing a relation between these 2 tables in the subquery. Update your question with table structure and the relation.

Other solution is : Use joins

SQL
SELECT t.mono,t.Fax,t1.Color,t1.Test,t.Name,t.Birthdate
 FROM Test t 
inner join Test1 t1 on t.ID = t1.ID
 
Share this answer
 
Hi,
You are not allowed to select multiple columns in sub query.
If you want to select a perticulate column then you have to give some common condition in sub query.
you can right

SQL
SELECT mono,Fax,
        (SELECT Color FROM Test1 where Test1.id = Test.ID),
        Name, Birthdate
        FROM Test;


OR If you want more coumns then you can right :

SQL
SELECT mono,Fax,
       (SELECT Color + ',' + Test FROM Test1 where Test1.id = Test.ID),
        Name, Birthdate
        FROM Test;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900