dkeeper09
dkeeper09

Reputation: 547

MYSQL Select from another column

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.

Upvotes: 1

Views: 384

Answers (2)

erewok
erewok

Reputation: 7835

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';

Upvotes: 3

Freddy Sidauruk
Freddy Sidauruk

Reputation: 292

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

Upvotes: 0

Related Questions