Jump to content

Recommended Posts

Hi all

 

I have the following QUERY

 

SELECT  *
FROM product_category_associations
INNER JOIN products ON product_category_associations.product_id = products.id
AND products.date_available <= '2008-11-05'
WHERE products.product LIKE '%Sample%'
AND `december` !=0
AND product_category_associations.live =1 GROUP BY `linked_id`
ORDER BY product_category_associations.live DESC

 

It returns something similar to

 

`product`        `linked_id`        `live`

iPod Nano          232                1

iPod Classic      112                  1

 

there is one more row in the database, but as it has a `live` value of 0, then it does not display (but for the record that row is)

 

`product`        `linked_id`        `live`

iPhone              232                0

 

If you notice, the 'iPhone' and 'iPod Nano' share the same `linked_id` (232) but because the 'iPhone' has a `live` value of 0 it's not returned in the main QUERY.

 

How can I alter my QUERY so that if the database finds that any rows with indentical `linked_id` values, and either of them have a `live` value of 0, then they won't display either, so in this case, because the `iPhone` has the same `linked_id` as the `iPod Nano`, but the `iPhone` has a `live` value of 0, then it won't display either of those rows, so if I ran the main QUERY again, it would just return

 

`product`        `linked_id`        `live`

iPod Classic      112                  1

 

Can anyone help?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/135319-query-help/
Share on other sites

Try this code in case if it works

 

SELECT  *
FROM product_category_associations, products where product_category_associations.product_id = products.id AND products.date_available <= '2008-11-05' and products.product LIKE '%Sample%' AND `december` !=0 AND product_category_associations.live =1 GROUP BY `linked_id`
ORDER BY product_category_associations.live DESC

 

For mysql help for visit at http://mysqlandphp.net

Link to comment
https://forums.phpfreaks.com/topic/135319-query-help/#findComment-707580
Share on other sites

Try this code in case if it works

 

SELECT  *
FROM product_category_associations, products where product_category_associations.product_id = products.id AND products.date_available <= '2008-11-05' and products.product LIKE '%Sample%' AND `december` !=0 AND product_category_associations.live =1 GROUP BY `linked_id`
ORDER BY product_category_associations.live DESC

 

For mysql help for visit at http://mysqlandphp.net

How is that helpful? We just metioned above that you CAN'T use * with GROUP BY...

Link to comment
https://forums.phpfreaks.com/topic/135319-query-help/#findComment-708927
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.