Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/236201-help-with-a-query/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214427
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214429
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214481
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214490
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/236201-help-with-a-query/#findComment-1214496
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.