bigdspbandj Posted October 23, 2007 Share Posted October 23, 2007 I am having troubles with this query: I have two tables: Jobs ----------- id login_id info1 info2 info3 Logins ----------- id customer_id info1 info2 info3 I am trying to write a query that selected all info from the jobs table where the logins.customer_id = a certain value, but the query keeps returning every record in jobs. Here is the query I have as of right now. Please help! SELECT * FROM d_jobs, d_logins WHERE d_logins.cust_id = 3; Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/74466-solved-sql-query/ Share on other sites More sharing options...
adam291086 Posted October 23, 2007 Share Posted October 23, 2007 when you set up the msql database are you sure you linked the tables? Quote Link to comment https://forums.phpfreaks.com/topic/74466-solved-sql-query/#findComment-376255 Share on other sites More sharing options...
BlueSkyIS Posted October 23, 2007 Share Posted October 23, 2007 you need to define the relation between the tables in your SQL: SELECT * FROM d_jobs, d_logins WHERE d_logins.cust_id = 3 AND d_logins.id = d_jobs.login_id; or however your tables are related. if your tables are not related, you'll need to add a relation Quote Link to comment https://forums.phpfreaks.com/topic/74466-solved-sql-query/#findComment-376257 Share on other sites More sharing options...
bigdspbandj Posted October 23, 2007 Author Share Posted October 23, 2007 Would you know how or have a link to the mysql resource of how I can add a relationship? I never quite figured that out. Can it be done through phpMyAdmin? Quote Link to comment https://forums.phpfreaks.com/topic/74466-solved-sql-query/#findComment-376305 Share on other sites More sharing options...
bigdspbandj Posted October 23, 2007 Author Share Posted October 23, 2007 Nevermind. I figured it out. Thanks! I still need query that pulls all jobs for a particular customer. I should say I have three tables jobs, logins, and customers. jobs contains a FK for logins and logins contains a FK for customers. Quote Link to comment https://forums.phpfreaks.com/topic/74466-solved-sql-query/#findComment-376310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.