Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    how to get a column with two results as only one

    I think I've boiled this down a simple query, to figure things out.

    I have a table that contains

    Code:
    plant_id    |   term_id
    ------------+----------------
    133477      |       4
    137036      |      543
    137049      |      4
    137049      |      543
    137056      |      4
    137149      |      4
    137149      |      543
    If I run a query like this:

    Code:
    SELECT DISTINCT GROUP_CONCAT( plant_id ) AS results
    FROM `termin_connect_to_plants`
    WHERE `term_id`
    IN (
    '4', '543'
    )
    GROUP BY `plant_id`
    ... I get a set of results like this... (but how do I do this??)

    results
    ------------
    133477
    137036
    137049,137049
    137056
    137149,137149


    What I want is to only get this:

    results
    ------------
    137049
    137149

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Code:
    SELECT plant_id, COUNT( DISTINCT plant_id ) AS results
    FROM termin_connect_to_plants 
    WHERE term_id IN ( 4, 543 )
    GROUP BY plant_id
    HAVING resuluts = 2
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •