skip to Main Content

enter image description here

My table has data as shown in the picture.
I selected the SiteInstanceID value based on a selection from another column "AttributeValue".

SELECT
   `SiteInstanceID` 
FROM
   `sitecomponentattributevalues` 
WHERE
   `AttributeValue` = 00069

Now I want to select all data from the same table where the SiteInstanceID is 61 (the extracted value from the above code)

enter image description here

2

Answers


  1. You can use exists:

    select s.*
    from sitecomponentattributevalues s
    where exists (
        select 1 
        from sitecomponentattributevalues s1 
        where s1.SiteInstanceID = s.SiteInstanceID and s1.AttributeValue = '0069'
    )
    
    Login or Signup to reply.
  2. you can join both SELECT statements with WHERE IN like this

    SELECT * FROM `sitecomponentattributevalues`
    WHERE `SiteInstanceID` IN 
    (SELECT `SiteInstanceID` FROM `sitecomponentattributevalues`
    WHERE `AttributeValue` = 00069)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search