1

Ok I have two tables. First table is fmp_leads. Second table is sic_codes

fmp_leads has a bunch of lead data, including a column called sic_code

sic_codes has 3 columns (id, sic_code, good_bad)

I want to run this:

SELECT * 
FROM fmp_leads 
WHERE (
    fmp_leads.sic_code MATCHES sic_codes.sic_code 
    AND sic_codes.good_bad = good
)

I realize that statement above isn't real, I'm just not sure how to perform the WHERE statement.

1
  • can you describe all table and show how it looks like ? Commented Feb 24, 2016 at 4:13

2 Answers 2

3

You probably want to JOIN the two tables ON the field you care about and use = in your WHERE clause:

SELECT * FROM fmp_leads fmp
JOIN sic_codes sic
ON fmp.sic_code = sic.sic_code 
WHERE sic.good_bad = 'good';
Sign up to request clarification or add additional context in comments.

1 Comment

Beautiful. I just had to add single quotes around the last 'good'. Thank you.
0

well this is another way to get data you want to,

  1. fmp_leads as a
  2. sic_codes as b

when you are trying grab data from that table use where a.sic_code=b.sic_code

Here is all query

select * from fmp_leads a, sic_codes b 
where a.sic_code=b.sic_code and b.good_bad ='good'

Note : Just use operator and, or based on you need it and to prevent repeatation using order by id from main table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.