Jump to content

Three tables gives twin-rows


Mr_CHISOL

Recommended Posts

Hello there!I'm working on a component for Joomla!, it's a "quote handler" (I'm tired right now, it's 2am here...).I'm listing all quotes in a list (table: jos_kacquotes) and getting the name of the category it belongs to (table: jos_kacquotes_categories) and the user who added the quote (table: jos_users).In a normal case I use a seperatet query (one for each row..) when I list the quotes to get the username.(It isn't the best, partially because of the whole "seperate data from layout"-thing, but that's not the point)I get the catagory in the same query as I get the quotes:

SELECT a.*, b.cattitle FROM jos_kacquotes AS a LEFT JOIN jos_kacquotes_categories AS b ON b.id = a.categoryid  ...

But as I have added the abbility to sort by column, I need to include the user-table in that query to, and it's hete it gets tricky.Right now I have this query for that:

SELECT DISTINCT a.*, b.name, c.cattitle FROM jos_kacquotes AS a LEFT JOIN jos_kacquotes_categories AS c, jos_users AS b ON b.id = a.createdby OR c.id = a.categoryid ORDER BY a.createdby_str, b.name DESC

The problem with this query is that it returns "twin-rows" (each row twice).And I can't figure out how I'm going to make it work as I want...Thankfull for all ideas.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...