Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Get data from 2 tables
Message
From
07/02/2019 02:51:11
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Get data from 2 tables
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2008 R2
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01666006
Message ID:
01666006
Views:
70
Sir, I am using these codes with sqlserver 2008.

I am trying to get data from two tables like this
SELECT Date, DatePart(hour,Date) as Hr, reading
FROM TABLE1 A
WHERE Date = 

(SELECT Min(Date) as date
 FROM TABLE1 B
 WHERE DatePart(hour,A.Date)= DatePart(hour,B.Date) 

 union all

 SELECT Min(Date)as date
 FROM TABLE2 C
 WHERE DatePart(hour,A.Date)= DatePart(hour,C.Date)) 
but I am facing this error message


Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows or when the subquery is used as an expression.

How to overcome this?


But this query work fine
SELECT Date, DatePart(hour,Date) as Hr, reading
FROM TABLE1 A
WHERE Date = 

(SELECT Min(Date) as date
 FROM TABLE1 B
 WHERE DatePart(hour,A.Date)= DatePart(hour,B.Date) ) 
Please
Next
Reply
Map
View

Click here to load this message in the networking platform