Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I need a SQL query

  1. Feb 14, 2007 #1

    rdx

    User Avatar

    I get a list from a query. Let's say "SELECT name FROM foods WHERE type='fruit';" returns "apple, orange, banana"

    I get a list from another query, "SELECT name FROM concepts WHERE type='color';" returns "red, orange, yellow"

    Now what I want is to find the common element(s) in the two lists, in this case "orange."

    What is the most efficient way to do this? SQL queries or PHP nested loops, or ???

    Thanks.
     
  2. jcsd
  3. Feb 14, 2007 #2

    jim mcnamara

    User Avatar
    Science Advisor
    Gold Member

    Code (Text):

    SELECT name FROM foods WHERE type='fruit'
    INTERSECT
    SELECT name FROM concepts WHERE type='color';
     
  4. Feb 14, 2007 #3

    verty

    User Avatar
    Homework Helper

    I would have thought of using a join:

     
  5. Feb 14, 2007 #4

    rdx

    User Avatar

    It works well with MySQL. It will be a while before I have comparative stats but this certainly works easily. Thanks.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: I need a SQL query
  1. SQL basics (Replies: 4)

  2. SQL relationships (Replies: 3)

  3. Sql join? (Replies: 4)

  4. Need Help on SQL query (Replies: 3)

  5. SQL Help (Replies: 2)

Loading...