0

So I am getting an

"Unknown Column"

error in this code:

SELECT 
 cus_id,
 cus_name, 
 cus_phone 
FROM database.cus_info 
WHERE cus_updated=1 IN ('database.cus_address') # AND cus_id = (database.cus_info.cus_id)

basically I need it to look in a different table (cus_address) and under column (cus_updated) and need it to only grab (cus_name and cus_phone) if (cus_updated) = 1.

Any ideas would be greatly appreciated. Thank you in advance

  • 3
    Share the structure of these two tables please. And mention how these two tables are related – 1000111 Dec 28 '16 at 02:37
  • I made a couple updates to the above code to get a better idea, the two tables will share the same cus_id. I am not sure what you mean by sharing the structure of the two tables but there are many more columns that what I have listed but are not needed for what I am trying to accomplish. –  Dec 28 '16 at 02:51

1 Answers1

1

INNER JOIN can help you in this regard.

SELECT
 CI.cus_id,
 CI.cus_name,
 CI.cus_phone
FROM database.cus_info CI 
INNER JOIN database.cus_address CA ON CI.cus_id = CA.cus_id 
WHERE CA.cus_updated = 1;

I guess cus_updated field belongs to cus_address table.


If you are not familiar with JOIN then go through this post.

Community
  • 1
  • 1
1000111
  • 13,169
  • 2
  • 28
  • 37
  • Okay, thank you. I will give this a try tomorrow when I get back to work and will update once I find out how it works out. –  Dec 28 '16 at 02:59