Answer the question
In order to leave comments, you need to log in
How should the query be modified so that when fetching all records, the subquery returns one value for each tuple?
I have a query that works fine as long as there is only one entry in the table:
SELECT Waybill.Id
, Waybill.IMO
, Vessel.Name
, Waybill.loginManager
, User.Name
, Waybill.loginStorekeeper
, (SELECT DISTINCT(Name) FROM User, Waybill WHERE (Waybill.loginStorekeeper = User.login)) AS storekeeperName
, Waybill.Date
FROM Waybill, Vessel, User
WHERE Waybill.IMO = Vessel.IMO
AND Waybill.loginManager = User.Login
AND Waybill.loginManager = User.Login
ORDER BY Waybill.Id
Answer the question
In order to leave comments, you need to log in
The subquery that is inserted into the list of columns must return only ONE row.
either rewrite the subquery to return only one row anyway, or join it or the table.
Besides this subquery is not anchored to sampling tables in any way?? as intended?
what is the connection between the tables, what kind of tables? what should be the sample result?
Wangyu, which should be something like this:
SELECT
w.Id
,w.IMO
,v.Name
,w.loginManager
,um.Name AS managerName
,w.loginStorekeeper
,umk.Name AS storekeeperName
,w.Date
FROM Waybill w
INNER JOIN Vessel v ON w.IMO = v.IMO
INNER JOIN User um ON w.loginManager = um.Login
INNER JOIN User umk ON w.loginStorekeeper = umk.Login
ORDER BY w.Id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question