ace2721 Posted May 12, 2011 Share Posted May 12, 2011 Hi Guys I hope everyone is enjoying their day, I am having a few problems, I need help with a query what I need to do is display data from a table if two different fields in two different tables equal the same value. Table one has ID Title Course content table two has ID Title Start date End date I need a query that says if title from table one matches title from table 2 then it will display the start and end date from table two sorry if this is really simple I have tried but I am very new to this and it seems to be taking weeks to try and come up with an answer thanks guys, any help with be much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/ Share on other sites More sharing options...
HDFilmMaker2112 Posted May 12, 2011 Share Posted May 12, 2011 I'm not great at this either but I believe you're looking for something like this: SELECT Start Date AND End Date FROM table2 WHERE table1.title = table2.title Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214416 Share on other sites More sharing options...
ace2721 Posted May 12, 2011 Author Share Posted May 12, 2011 HI HD thanks for your help, I have tried your reply but I am getting an error 1054 unknown column table1.title in where clause I have made sure that the tables have all the required fields Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214426 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 12, 2011 Share Posted May 12, 2011 HI HD thanks for your help, I have tried your reply but I am getting an error 1054 unknown column table1.title in where clause I have made sure that the tables have all the required fields did you replace table1 and table2 with your actual table names? or are they actually called table1 and table2? Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214427 Share on other sites More sharing options...
ace2721 Posted May 12, 2011 Author Share Posted May 12, 2011 HI HD no the table layouts are the following table one id title course i_frame table two id startdate enddate course_id but I have changed the table names in the query, I just thought it would be easier to explain just to add to this I am running this query in phpadmin first to make sure it works, don't know if you need to know that Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214429 Share on other sites More sharing options...
ace2721 Posted May 12, 2011 Author Share Posted May 12, 2011 would I and could I use the join function for this query Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214474 Share on other sites More sharing options...
mikosiko Posted May 12, 2011 Share Posted May 12, 2011 something is no matching here.... In your first post you said that your tables layouts were like this: table one ID Title Course content table two has ID Title Start date End date and in your last post you said that the layouts are this table one ID Title Course i_frame table two has ID Start date End date course_id and you want to join by "title" .... ??? which one is your correct table layout? Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214481 Share on other sites More sharing options...
ace2721 Posted May 12, 2011 Author Share Posted May 12, 2011 Hi mikosiko I gave the first table as I thought it would be easy to explain sorry for the confusion the real table layout is table1 ID Title Course iframe_id table2 ID Start date End date course_id I need a query that say if the i_frame field in table one matches the course_id in table two then the startdate and enddate from table 2 is displayed Now when i try SELECT Start Date AND End Date FROM table2 WHERE table1.iframe_id = table2.course_id I get error 1054 unknown column table1.iframe_id in where clause but this def exists thanks again Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214490 Share on other sites More sharing options...
mikosiko Posted May 12, 2011 Share Posted May 12, 2011 SELECT `Start Date`, `End Date` FROM table1, table2 WHERE table1.iframe_id = table2.course_id which is equivalent to SELECT `Start Date`, `End Date` FROM table1 JOIN table2 ON table1.iframe_id = table2.course_id also if you really have the columns named like that, including spaces you must enclose them in backtics, but is much better if you don't use spaces in then names. Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214496 Share on other sites More sharing options...
ace2721 Posted May 12, 2011 Author Share Posted May 12, 2011 Hi mikosiko thank you so much, that worked straight way thanks again have a great day Quote Link to comment https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214505 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.