|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
WTF is wrong with my SQL query ???
#26498344 - 02/22/20 11:36 AM (4 years, 2 months ago) |
|
|
Im doing simple JOIN queries and i cant get past this example

Check a example how it should be done:
https://www.w3schools.com/sql/sql_join_inner.asp
SQL INNER JOIN Keyword The INNER JOIN keyword selects records that have matching values in both tables.
INNER JOIN Syntax
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
As you can see it identical to mine, the WTF is wrong??????? Is this a bug on side of SQL manager?
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: WTF is wrong with my SQL query ??? [Re: Gypsy Boy]
#26498347 - 02/22/20 11:38 AM (4 years, 2 months ago) |
|
|
Any help much appreciated
But i think proper way of doing this is going on reddit ...
--------------------
|
dogtomato
Stranger
Registered: 09/25/19
Posts: 3
Last seen: 3 years, 2 months
|
Re: WTF is wrong with my SQL query ??? [Re: Gypsy Boy]
#26498350 - 02/22/20 11:41 AM (4 years, 2 months ago) |
|
|
It's telling you "ambiguous" because the field name exists in both tables. You need to specify the field name - SELECT messages.forum_id FROM messages (etc.)
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: WTF is wrong with my SQL query ??? [Re: dogtomato]
#26498366 - 02/22/20 12:00 PM (4 years, 2 months ago) |
|
|
I dont get this:
I typed out the example EXACTLY as it appears in the book i got.
I tried
SELECT messages.forum_id FROM messages
It seems to work but i dont get it why. Like i said i typed it out exactly as appears in the book.
Why say "SELECT messages.forum_id" and then add FROM messages, why select messages.forum_id when i say FROM table messages already???
Anyway thanks for the help dude
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: WTF is wrong with my SQL query ??? [Re: Gypsy Boy]
#26498368 - 02/22/20 12:01 PM (4 years, 2 months ago) |
|
|
And what do u mean by field name?
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: WTF is wrong with my SQL query ??? [Re: Gypsy Boy]
#26498375 - 02/22/20 12:08 PM (4 years, 2 months ago) |
|
|
i think theres a typo in the book
--------------------
|
Gypsy Boy
Redeemer



Registered: 03/17/17
Posts: 4,501
Loc: Deep in the discoteka
Last seen: 6 months, 13 days
|
Re: WTF is wrong with my SQL query ??? [Re: Gypsy Boy]
#26498393 - 02/22/20 12:25 PM (4 years, 2 months ago) |
|
|
I think i got it
That example IS an error example!!!
--------------------
|
dogtomato
Stranger
Registered: 09/25/19
Posts: 3
Last seen: 3 years, 2 months
|
Re: WTF is wrong with my SQL query ??? [Re: Gypsy Boy]
#26498581 - 02/22/20 02:36 PM (4 years, 2 months ago) |
|
|
Yeah, and I get why it's confusing - you are saying "FROM messages" so in english it makes sense to think that's the only thing you're selecting FROM. But the way joins work is that you're actually joining two tables together - so what SQL sees is "SELECT .... FROM [messages INNER JOIN forums]" where the object you're selecting from is the two tables joined together as one. Hope that makes sense.
|
dogtomato
Stranger
Registered: 09/25/19
Posts: 3
Last seen: 3 years, 2 months
|
Re: WTF is wrong with my SQL query ??? [Re: dogtomato]
#26498586 - 02/22/20 02:38 PM (4 years, 2 months ago) |
|
|
Also, some people say fields, some people say columns... fields is less specific. A column is a field, but a field could be a column or a formula using columns... that's a whole other can 'o worms!
|
|