News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

[SQL] Join On - correct syntax?

Started by Tristan Perry, October 14, 2006, 04:31:21 AM

Previous topic - Next topic

Tristan Perry

Hey all,
I've been trying to get better at SQL queries (I suck at them!) but have hit a little bump. I can't seem to get JOIN SQL queries to work. The following works:

SELECT jokes.Name, jokes.Joke, jokes.Activated, jokecat.Name
FROM jokes, jokeCat
WHERE jokes.MemberID = '1'
AND jokes.CategoryIn = jokecat.ID


but this doesn't:

SELECT jokes.Name, jokes.Joke, jokes.Activated, jokecat.Name
FROM jokes, jokeCat
WHERE jokes.MemberID='1'
JOIN jokecat
ON jokes.CategoryIn=jokecat.ID


Any ideas why and help would be greatly appreciated :)
Thanks,
Tau Online

Remaker

try this  :-\

SELECT jokes.Name, jokes.Joke, jokes.Activated, jokecat.Name
FROM jokes, jokeCat
JOIN jokecat ON jokes.MemberID='1' AND jokes.CategoryIn=jokecat.ID
Remaker - My blog

Tony Reid

I found this (FREE) visual query tool a great help when starting out with queries.

http://crlab.com/mybuilder/

You may need to download .net framework (if your not running XP sp2)- but they provide a link.

They also do another product for $49 which has that tool built in + others ;)
http://crlab.com/mysqldev/

Tony Reid

Tristan Perry

Quote from: Remaker on October 14, 2006, 05:31:30 AM
try this  :-\

SELECT jokes.Name, jokes.Joke, jokes.Activated, jokecat.Name
FROM jokes, jokeCat
JOIN jokecat ON jokes.MemberID='1' AND jokes.CategoryIn=jokecat.ID

Thanks for that, although it gives the error "Not unique table/alias: 'jokecat'"?

Quote from: Tony on October 14, 2006, 05:40:30 AM
I found this (FREE) visual query tool a great help when starting out with queries.

http://crlab.com/mybuilder/

You may need to download .net framework (if your not running XP sp2)- but they provide a link.

They also do another product for $49 which has that tool built in + others ;)
http://crlab.com/mysqldev/


Ah that should be very helpful, thanks :)

Advertisement: