|
-
Jul 22nd, 2003, 07:58 PM
#1
Thread Starter
Lively Member
Special Join for MySQL (RESOLVED)
Hi everyone,
Ok, I'm going to try and explain this as best as possible and show lots of examples to try and be concise. I have two tables, that looks like this:
tblSection
fldSection fldName
--------------------------
1 General
2 Romance
3 Sci-Fi
4 Fantasy
tblCredit
fldClient fldSection fldCredit
-----------------------------------------
1 2 20
1 4 24
What I would like to do is connect these two tables, show all sections, and base it off of the Client number. The output I'm looking for would be this:
fldSection fldName fldCredit
-----------------------------------------
1 General 20
2 Romance 24
3 Sci-Fi
4 Fantasy
This information would be based off of the client id which is 1 in the tblCredit table.
I've tried several different variations of joins (left, right, outer, etc), but to no avail. If anyone could help me, I'd appreciate it greatly. Thank you!!!
Last edited by mccareth; Jul 23rd, 2003 at 10:07 AM.
-
Jul 23rd, 2003, 03:25 AM
#2
Frenzied Member
SELECT c.fldSection, s.fldName, c.fldCredit FROM tblCredit AS c LEFT OUTER JOIN tblSection AS s ON c.fldSection = s.fldSection WHERE c.fldClient = 1 ORDER BY c.fldSection
-
Jul 23rd, 2003, 08:33 AM
#3
Thread Starter
Lively Member
Unfortunately, that only does the following...
fldSection fldName fldCredit
-----------------------------------------------------
1 General 20
2 Romance 24
It doesn't show the other sections of Sci-Fi and Fantasy.
-
Jul 23rd, 2003, 08:57 AM
#4
Frenzied Member
-
Jul 23rd, 2003, 09:38 AM
#5
Thread Starter
Lively Member
MySQL doesn't seem to like FULL for some reason.
-
Jul 23rd, 2003, 09:44 AM
#6
Frenzied Member
Try RIGHT OUTER JOIN but I'm sure LEFT OUTER JOIN is the one that does that for SQL Server - might be worth investigating the MySQL manual to check it isn't implimented differently.
-
Jul 23rd, 2003, 09:47 AM
#7
Thread Starter
Lively Member
Right Outer Join does the same thing, and unfortunately MySQL is not very helpful with it's instructions in it's manual. Here is what they have on joinshttp://www.mysql.com/doc/en/JOIN.html
-
Jul 23rd, 2003, 09:52 AM
#8
Frenzied Member
The OUTER JOIN should return all records. If one of the records from one of the linked tables doesn't exist then null values should be put into the returned set. The LEFT, RIGHT and FULL just states which tables are allowed to return null values. FULL should cover every case. Dunno if its worth just trying a OUTER JOIN?
-
Jul 23rd, 2003, 10:04 AM
#9
Thread Starter
Lively Member
I FINALLY figured it out... It's a little wonky, but it does work..
SELECT tblSection.fldSection, tblSection.fldName, tblCredit.fldCredit FROM tblSection LEFT JOIN tblCredit ON (tblSection.fldSection=tblCredit.fldSection AND tblCredit.fldClient=1)
This works. and quite nicely. I found an odd little blurb about a similar problem for someone else and tried it out.
-
Jul 23rd, 2003, 10:06 AM
#10
Thread Starter
Lively Member
By the way, dj4uk, thank you for all your help. It was very much appreciated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|