I have 2 tables
Instead of Currency1Id and Currency2Id, I want to show the CurrencyShortcut just to make it look better
In any case I managed to join only one of the fields like this :
Please help me convert both of them to the values for the currency table
Thanks !!
I think what you need is something like this
SELECT c1.CurrencyShortcut [Currency1], c2.CurrencyShortcut [Currency2]
/*, other columns you need*/
FROM Spot as s
JOIN Currencies as c1 ON s.CurrencyId = c1.CurrencyId
JOIN Currencies as c2 ON s.CurrencyId = c2.CurrencyId
You can alias your columns too..
SELECT
c1.Currency1Id AS Currency1Shortcut
, c2.Currency2Id AS Currency2Shortcut
Related
What do I have to change to get different results from different names.The table should give me the debts of each of them, this is calculated by the amount and the price of the drink. Now it should show all the names with the corresponding invoice that happens after the select
%sql select name, sum(getraenk.preis*schulden.menge) schulden from schulden \
join person on (fk_person = person.id)\
join getraenk on (fk_getraenk = getraenk.id)\
where name like ("dani")
Edit: it should spend all the names with their debts, that is:
dani = 8.5
michael = 12.5
...
Just in case your problem is very simple, you should be able to see all names and values with an SQL that looks like this:
select name, getraenk.preis*schulden.menge schulden
from schulden
join person on (fk_person = person.id)
join getraenk on (fk_getraenk = getraenk.id)
Note that I removed the where clause... this was the part that limited it to one name.
You also don't need the sum clause here unless you are doing a group by
Have you considered simply using GROUP BY name at the end of this query?
https://www.w3schools.com/sql/sql_groupby.asp
This will give you the sum of total debt for all names in your table which sounds like the result you are looking for.
You're missing
GROUP BY name
in the query.
I'm trying to find a way to find a way to compare two queries that use a combine sent of criteria. In this case we have Prefixes (Two letter code like DA) and Pack number 1234567. In the query I've created a field that combines these two things so it appears 1234567DA this is done with each of the queries from the separate tables they are pulled from. The idea is that if this is in one table and not the other it would show up as "False". I tried to use an Unmatched query but that doesn't seem to work. What I have currently is as follows:
SELECT
[1LagoTest].Prefix,
[1BigPicPackPref].BigPicPP,
IIf([BigPicPP]=[LagoPP],"True","False") AS Compare,
[1LagoTest].RETAIL,
[1LagoTest].MEDIA
FROM 1LagoTest
LEFT JOIN 1BigPicPackPref
ON [1LagoTest].[Prefix] = [1BigPicPackPref].[BigPicPP]
WHERE (((IIf([BigPicPP]=[LagoPP],"True","False")) Like "False")
AND (([1LagoTest].MEDIA) Not Like "*2019 FL*"))
ORDER BY [1LagoTest].RETAIL;
Right now it will show whats missing from LagoPP but doesn't give me anything from missing packs in BigPicPP. Any help in the right direction would be greatly appreciated.
Thanks!!
This gets a little tricky in Access without FULL OUTER JOIN, but the general idea to is replicate a FULL OUTER JOIN using UNION ALL, then filter from that.
Something like this:
SELECT I.Prefix,
I.BigPicPP,
I.Compare,
I.Retail,
I.Media
FROM (SELECT L.Prefix,
B.BigPicPP,
IIf([BigPicPP]=[LagoPP],"True","False") as Compare,
L.Retail,
L.Media
FROM 1LagoTest L
JOIN 1BigPicPackPref B ON L.Prefix = B.BigPicPP
WHERE L.Media NOT LIKE "*2019 FL*"
UNION ALL
SELECT L.Prefix,
B.BigPicPP,
"False", --Missing records from 1BigPicPackPref
L.Retail,
L.Media
FROM 1LagoTest L
LEFT JOIN 1BigPicPackPref B ON L.Prefix = B.BigPicPP
AND L.Media NOT LIKE "*2019 FL*"
WHERE B.Prefix IS NULL
UNION ALL
SELECT B.Prefix,
B.BigPicPP,
"False", --Missing records from 1LagoTest
L.Retail,
L.Media
FROM 1LagoTest L
RIGHT JOIN 1BigPicPackPref B ON L.Prefix = B.BigPicPP
AND L.Media NOT LIKE "*2019 FL*"
WHERE L.Prefix IS NULL
) AS I
You only need IFF in the first part of the union because in the second two parts one side will always be NULL, so we know the compare will always fail and be False.
You shouldn't need this part of your current WHERE clause at all (((IIf([BigPicPP]=[LagoPP],"True","False")) Like "False"). But if you only want to see False records, just add WHERE I.Compare = "False" to the bottom of the outer select.
The reason the "Unmatched" query (assuming through the Wizard) does not work, is because you are attempting to see the values of two separate tables / queries that do not match either table / query. This is not how the "Unmatched" works. All that will give you is a single table / query that does not match another single table / query.
This can most likely be done any number of ways, but this would probably get you where you want to be (or close to it):
SELECT
a.Prefix,
b.BigPicPP,
IIf([BigPicPP]=[LagoPP],"True","False") AS Compare,
a.RETAIL,
a.MEDIA
FROM [1LagoTest] a
LEFT JOIN [1BigPicPackPref] b ON a.Prefix = b.BigPicPP
WHERE a.MEDIA Not Like "*2019 FL*"
AND b.BigPicPP IS NULL
ORDER BY a.RETAIL
UNION
SELECT
a.Prefix,
b.BigPicPP,
IIf([BigPicPP]=[LagoPP],"True","False") AS Compare,
a.RETAIL,
a.MEDIA
FROM [1LagoTest] a
RIGHT JOIN [1BigPicPackPref] b ON a.Prefix = b.BigPicPP
WHERE a.MEDIA Not Like "*2019 FL*"
AND a.Prefix IS NULL
ORDER BY a.RETAIL
NOTE: Depending on the data structure, the ORDER BY may cause some issues.
So the way I got this to finally work was to build two separate queries. One looking at what was missing from Lago and One that was looking at what was missing from BigPic. It was the only way I could get it to give me both sets of missing data. If I can find a better way to do it through one query I will report back as I'm still gonna play around with it.
My first table (actually a view) is:
SELECT * FROM VW_MAIN_INFO
My second table is:
SELECT * FROM TBL_POINTS_AND_CYCLES
In a query, I combine both like this:
SELECT TP.TYPE,VMI.*
FROM VW_MAIN_INFO VMI,
TBL_POINTS_AND_CYCLES TP
WHERE VMI.START_INLET_TEMP=TP.TEMP1
AND VMI.START_OUTLET_TEMP=TP.TEMP2
AND VMI.TIME_FORMATTED=CONVERT(DATETIME, TP.DATE, 101)
What you can tell, what really matters for me in the second table (TBL_POINTS_AND_CYCLES) is the field "TYPE".
What do I need help with:
I need to return everything from VW_MAIN_INFO and TYPE (from TBL_POINTS_AND_CYCLES).
However, if I cannot find a type in TBL_POINTS_AND_CYCLES, I should return a specific value (for example, "EMPTY" or null).
How can I achieve? Is the best path to use "minus" like this?
Finally, my problem with minus is that I don't have the same structure in both tables.
Any help? Ideas?
Thank you.
SELECT TP.TYPE ,
VMI.*
FROM VW_MAIN_INFO VMI
LEFT JOIN TBL_POINTS_AND_CYCLES TP ON VMI.START_INLET_TEMP = TP.TEMP1
AND VMI.START_OUTLET_TEMP = TP.TEMP2
AND VMI.TIME_FORMATTED = CONVERT(DATETIME, TP.DATE, 101);
I have two tables which are question_table and student_response( like in the images below). I am having a trouble to come up with a query which can pull out Question, ChosenOption(this will display the actual option from question_table, not just OptionA,OptionB...), and TextResponse. Any help or tip is appreciated. Thank you so much !
http://i.stack.imgur.com/kthi1.png
http://i.stack.imgur.com/oXPiX.png
do you mean you want something like this?
select * from question_table,chosen_table where question_table.QuestionID=chosen_table.ID
or
select * from chosen_table join question_table on chosen_table.QuestionID = question_table.ID
Use the next
SELECT q.*,sr.choosenoption
FROM question_table q
INNER JOIN student_response sr ON sr.questionID=q.ID
probably your question will be deleted or something ... is basic SQL logic and also you don't put proper tags.
Put mysql tag on your question :)
I have a query here that doesn't work and having trouble pin pointing my mistake.
Any help would be great.
Thanks
I am trying to retrieve records with a program name starting with 'C' but my query returns zero records.
My PROGRAM table has an entry of a ProgName of Chemistry.
SELECT P.ProgNumber, ProgName, StudID, DateEnrolled
FROM PROGRAM AS P, STUDENT AS S
WHERE P.ProgNo = S.ProgNo
AND ProgName LIKE 'C%';
Use
LIKE "C*"
MSAccess doesn't use % as the wildcard
SELECT
P.ProgNumber, P.ProgName, S.StudID, S.DateEnrolled
FROM
PROGRAM P
JOIN STUDENT S ON S.ProgNo = P.ProgNo
WHERE
P.ProgName LIKE 'C%';
should work... you said you changed it to ='Chemistry', do you get the same result if you use lowercase c in chemistry?
You need to join the different tables like this...Try this...
SELECT P.ProgNumber, P.ProgName, S.StudID, S.DateEnrolled
FROM PROGRAM P
JOIN STUDENT S
ON P.ProgNo = S.ProgNo
WHERE P.ProgName LIKE 'C*'; -- Asterisk because its Access not MS-SQL