Not sure how to work this but I found a way that works although some of the columns have incorrect data in them. So for now, I’ll leave this with a SOLVED indication but I may need this documentation for other assistance. It could be deleted though.
Sorry, but I don’t think that the answer lies in the “questions with similar titles”. I could well be wrong but I have searched and searched for documentation I can understand but it’s probably like my old days with the IBM manuals for main frames. If you don’t know the exact word you won’t find the answer.
So here goes:
SELECT * FROM membership LEFT JOIN address2 USING(memno)
CROSS JOIN contact USING(memno)
CROSS JOIN workers USING(memno)
CROSS JOIN comments USING(memno)
JOIN candidates USING(memno)
Tried this a number of ways. I thought about saying I tried it every way possible but I obviously did not do it the right way at least. When I do just the first line I get all the right columns and I get all five rows of the tables in my db.
When I add the second line it works but I only get two rows. It works through the “comments” line. It doesn’t do the last line “candidates”.
What I need to be getting is all five rows (the number of rows in the membership table).
Cross join is one problem. I think that it limits the rows as there are only two rows in one of the tables and it goes both ways on the limits.
So I think that what I need is the correct JOIN for the second, third, and fourth line and likely another JOIN type for the last line.
I have very limited hair to tear out so I need your help please.
Well, without knowing your table schema, data nor having a clear expected result it is a bit difficult to guess what you’re looking for. But this will get you all rows from the membership table regardless of whether they have a match or not on the other tables:
Edit:
Personally, I wouldn’t trust
USINGwhen using chained left joins like this. I would make sure by explicitly adding the table to join:I scanned the documentation on
USINGand couldn’t find any reference to this, but I meant that I’m not sure from which table it chooses the columns. This:Is using alias
mas the left part of the left join, so I’m sure I’ll see all memebers, regardless of the fact that thay have or not a contact or an address. However, this:Is not clear on from what table is using the
memnowhen joining withcontact. In the first left join of the previous example there is no other table to choose so it will joinmandaandmwill be the left part. But when joiningcyou will have 2memno:m.memnoanda.memno. If theUSINGchoosesm, then the query will be the same, but if it choosesc, the previous query will translate to:I think this is not what you’re looking for. Don’t think it is a bad practice specifying the fields and the tables they come from… the intentions are clearer that way.