SELECT WHERE IN

  • Hi,

    I've got 2 tables and I want to return data where a value is also in another table. I'm using the following:

    SELECT tagname FROM history

    WHERE tagname IN (SELECT tagname FROM livedata)

    AND value = 1

    This created a never ending loop, if I replace the SQL in the brackets to valid data such as 'system', 'harddrive', 'cpu' then it works fine.

  • try this one .........

    SELECT tagname FROM history as h

    inner join livedata as l on l.tagname = h.tagname

    where value = 1

  • Hi,

    Thanks for this, unfortunately it appears I'm having issues with my laptop and as such its throwing up stupid errors like ambiguous column name even though I know it exists. I'll let you know how I get on 🙂

  • A slight alteration on that query:

    SELECT h.tagname FROM history as h

    inner join livedata as l on l.tagname = h.tagname

    where value = 1

    It's not that it can't find the fieldname it's that it can find both fields. You have to specify which tagname to use.

  • cheers, but I think its also an issue with my laptop, the history table cannot be found now 🙂 Think a format is in order!!

  • Hi Peter,

    I suggest making sure you are connected to the correct DB before going through with your format!

    Thanks

    Chris

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life
  • hehe yes I am, the laptop is slowly griding to a halt as software is added and removed constantly. I'm behind on the quarterly format anyway 🙂

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply