tags:

views:

14

answers:

2

I have two tables. Lets say they look like this

Table Sports:
Column 1: id (integer)
Column 2: name (varchar 100)

Table Sport Articles:
Column 1: id (integer)
Column 2: data (text)
Column 3: sport (integer)

So what I want to do is select things from the sports articles. lets say I have the ID number already. all i want is the data and the name of the sport.

So i want to select data from Sport articles where id = some number I already have, and name from Sports where id = sport from sport articles.

I think it uses the using keyword so my guess would be:

SELECT sportsarticles.data, sportsarticles.sport as sportid WHERE sportsarticles.id=5 AND sports.id=sportid
A: 

Yes. It is ok.

SELECT DISTINCT sports.id, sportsarticles.data 
FROM sportsarticles, sports
WHERE sports.id = (YOURID) 
   AND sports.id = sportarticles.sports
Muneer
SELECT sportsarticles.id, sportsarticles.title, sportsarticles.teaser, sports.name FROM sportsarticles, sports WHERE sportsarticles.issue=? AND sports.id=sportsarticles.sport ORDER BY RAND() LIMIT 4 --- this selects 4 random articles perfectly thanks
my name
+1  A: 
SELECT sports.name, 
       sportsarticles.data, 
       sportsarticles.sport AS sportid 
FROM   sports 
       INNER JOIN sportsarticle 
         ON sportsarticle.id = sports.id 
WHERE  sportsarticles.id = 5 
nos