Jump to content

Help with switch query


studgate

Recommended Posts

Hi Guys,

  I am trying to get some help with a query that I am working on.

I have two tables, posted here:

CREATE TABLE `sessions` (
  `sessionsid` int(11) NOT NULL auto_increment,
  `sessionsname` varchar(255) NOT NULL default '',
  `sport` int(11) NOT NULL default '1',
  KEY `confid` (`sessionsid`)
);

&

CREATE TABLE `sports` (
  `sportsid` int(11) NOT NULL auto_increment,
  `sportsname` varchar(50) default NULL,
  PRIMARY KEY  (`sportsid`)
);

 

What I want to do is to get a list of all the items in table one(sessions) which

has

sessions.sport = sports.sportsid.

Thank you in advance.

 

Link to comment
Share on other sites

Your question is not making sense as posed. You have to have some value that you are comparing against which would lead to a simple query such as:

 

SELECT *

FROM `sessions`

WHERE `sport` = $somevalue

 

If you are wanting to JOIN the two tables then what is the supplied value you are going to search on - sportsname? In that case the query would look like this:

 

SELECT *

FROM `sessions`

JOIN `sports` ON sessions.sport = sports.sportsid

WHERE `sportname` = $searchvalue

 

However, I would recommend changing the value of `sport` to `sportid` in the `sessions` table, because that is what it is. makes it a lot easier to coordinate the tables.

Link to comment
Share on other sites

the tables are joined together, when I add an entry to the

sessions tables, the sportsid of the second one is added in

the sport table.

And I want to be able to get a list of all the data in sessions

table that match the second table id

 

Link to comment
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.