Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Query Multiple Fields

Status
Not open for further replies.

nike2000

Technical User
Apr 1, 2003
61
GB
I have three tables in a query the SQL is:

SELECT
Tbl_Trades.[MAD No],
Tbl_Trades.[FRD No],
Tbl_Trades.[Analytic Direction],
Tbl_Trades.Ptf,
Tbl_PortfolioLocations2C.Location,
Tbl_Trades.[Portfolio 2],
Tbl_PortfolioLocations2C_1.Location

FROM Tbl_PortfolioLocations2C AS Tbl_PortfolioLocations2C_1 INNER JOIN (Tbl_Trades INNER JOIN Tbl_PortfolioLocations2C ON Tbl_Trades.Ptf = Tbl_PortfolioLocations2C.Ptf) ON Tbl_PortfolioLocations2C_1.Ptf = Tbl_Trades.[Portfolio 2]

GROUP BY
Tbl_Trades.[MAD No],
Tbl_Trades.[FRD No],
Tbl_Trades.[Analytic Direction],
Tbl_Trades.Ptf,
Tbl_PortfolioLocations2C.Location,
Tbl_Trades.[Portfolio 2],
Tbl_PortfolioLocations2C_1.Location;

=====================================================

For the fields Location (it appears in two Tables; Tbl_PortfolioLocations2C and Tbl_PortfolioLocations2C_1) I would like it to only show the records where London appears in either of the two fields, not if it appears in both.

How can this be written??
Thanks,
Nike
 
WHERE
(PortfolioLocations2C.location = &quot;London&quot; AND PortfolioLocations2C_1.location <> &quot;London&quot;)
OR
(PortfolioLocations2C.location <> &quot;London&quot; AND PortfolioLocations2C_1.location = &quot;London&quot;)


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Hi,
Apologies for posting twice.

The query threw back an error message:
'Syntax error (missing operator) in query expression'

The SQL of the query is:

SELECT
Tbl_Trades.[MAD No],
Tbl_Trades.[FRD No],
Tbl_Trades.[Analytic Direction],
Tbl_Trades.Ptf,
Tbl_PortfolioLocations2C.Location,
Tbl_Trades.[Portfolio 2],
Tbl_PortfolioLocations2C_1.Location

WHERE (PortfolioLocations2C.location = &quot;London&quot; AND PortfolioLocations2C_1.location <> &quot;London&quot;) OR
(PortfolioLocations2C.location <> &quot;London&quot; AND PortfolioLocations2C_1.location = &quot;London&quot;)

FROM Tbl_PortfolioLocations2C AS Tbl_PortfolioLocations2C_1 INNER JOIN (Tbl_Trades INNER JOIN Tbl_PortfolioLocations2C ON Tbl_Trades.Ptf = Tbl_PortfolioLocations2C.Ptf) ON Tbl_PortfolioLocations2C_1.Ptf = Tbl_Trades.[Portfolio 2]

GROUP BY
Tbl_Trades.[MAD No],
Tbl_Trades.[FRD No],
Tbl_Trades.[Analytic Direction],
Tbl_Trades.Ptf,
Tbl_PortfolioLocations2C.Location,
Tbl_Trades.[Portfolio 2],
Tbl_PortfolioLocations2C_1.Location;

Could you take a look?
Thanks,
Nike


 
FROM before WHERE....

SELECT
Tbl_Trades.[MAD No],
Tbl_Trades.[FRD No],
Tbl_Trades.[Analytic Direction],
Tbl_Trades.Ptf,
Tbl_PortfolioLocations2C.Location,
Tbl_Trades.[Portfolio 2],
Tbl_PortfolioLocations2C_1.Location

FROM Tbl_PortfolioLocations2C AS Tbl_PortfolioLocations2C_1 INNER JOIN (Tbl_Trades INNER JOIN Tbl_PortfolioLocations2C ON Tbl_Trades.Ptf = Tbl_PortfolioLocations2C.Ptf) ON Tbl_PortfolioLocations2C_1.Ptf = Tbl_Trades.[Portfolio 2]

WHERE (PortfolioLocations2C.location = &quot;London&quot; AND PortfolioLocations2C_1.location <> &quot;London&quot;) OR
(PortfolioLocations2C.location <> &quot;London&quot; AND PortfolioLocations2C_1.location = &quot;London&quot;)

GROUP BY
Tbl_Trades.[MAD No],
Tbl_Trades.[FRD No],
Tbl_Trades.[Analytic Direction],
Tbl_Trades.Ptf,
Tbl_PortfolioLocations2C.Location,
Tbl_Trades.[Portfolio 2],
Tbl_PortfolioLocations2C_1.Location;


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top