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
https://forums.phpfreaks.com/topic/96455-help-with-switch-query/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.