Jump to content

query - returning 1 row


Destramic

Recommended Posts

SELECT i.item_id, 
		         i.title, 
		         i.price,
		         i.p_and_p,
		         SUM(i.price + i.p_and_p) AS `total_price`,
		         i.listing,
		         i.condition,
		         i.start_date_time,
		         i.listing_duration,
		         CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time`
		  FROM items i
		  LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id
		  LEFT JOIN categories c ON c.name = 'test'
		  JOIN users u
		  WHERE u.username = 'Destramic'
		  AND i.start_date_time < NOW() 
		  AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW()

I'm having a problem with my query returning more than 1 rows...I've even copied the row which is returning to see if that'll return 2 rows but it doesn't

 

can anyone explain why this is happening please?

 

 

Link to comment
Share on other sites

and as mentioned in a previous thread, you are not specifying join conditions fully, which is resulting in every row from the left-hand side of the join being joined to every row on the right-hand side of the join without regard to the relationship between those rows.

 

LEFT JOIN categories c ON ... needs to specify how you want to join the item/sub-category information to the category table.

 

JOIN users u ... needs to specify how you want to join the item/sub-category/category information to the users table.

 

lastly, concat(i.listing_duration) <- that's concatenating one value. why not just use the value itself?

Link to comment
Share on other sites

thanks @barand

 

oh ok so if I do

LEFT JOIN categories c ON c.category_id = sc.category_id

WHERE c.name = 'test'

and something similar for users?

 

regarding concat() it was the only way I could get the query working as the field list_duration is a enum just using the value of the field wasn't working

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.