|
Posted by J.O. Aho on 07/18/06 14:59
Frankly wrote:
> "J.O. Aho" <user@example.net> wrote in message
> news:4fo8qhF1jvtpeU1@individual.net...
>> If you think you never will post it at more places than 10, then okey, but
>> you can also create a new table where you save the apartmentid and the
>> website where you posted the ad to, this way you can have more places to
>> advertise at than ten (I hope I didn't misunderstand you here).
>
> this new table will require an inner join to the Apartments table. ?
> lets call it NewTable.
>
>
> Select Apartments.ApartmentID, NewTable.ApartmentID,
> from Apartments, NewTable
> where Apartments.ApartmentID = NewTable.ApartmentID;
The "Select Apartments.ApartmentID, NewTable.ApartmentID" is a bit bad, as you
are joining the tables, you will get the same result in those two columns, so
a "Select Apartments.ApartmentID" or "Select NewTable.ApartmentID" would be
better. Of course as testing and learning to understand how things works it's
okey to get both ApartmentID's.
SELECT Apartments.ApartmentID FROM Apartments, NewTable WHERE
Apartments.ApartmentID = NewTable.ApartmentID;
This requires that you have the same ID's in both tables
Apartments.ApartmentID
1
2
3
4
5
NewTable.ApartmentID
1
2
3
4
5
Then in your joint table you will get
ApartmentID
1 - 1
2 - 2
3 - 3
4 - 4
5 - 5
If you do not have the same ID's in the tables
Apartments.ApartmentID
11
21
31
41
51
NewTable.ApartmentID
12
22
32
42
52
Then in the joint table you will get
ApartmentID
<no results>
If you want to join anyway and get results, then you will need to use outer joins.
SELECT Apartments.ApartmentID FROM Apartments LEFT JOIN NewTable ON
(Apartments.ApartmentID = NewTable.ApartmentID);
This way all ID's in the Apartments will appear and those ID's that are the
same in the NewTable as in Apartments.
Apartments.ApartmentID
11
21
31
41
51
NewTable.ApartmentID
11
12
13
14
15
ApartmentID
11 - 11
21 - NULL
31 - NULL
41 - NULL
51 - NULL
For more detailed info, you can take a look at
http://dev.mysql.com/doc/refman/5.0/en/join.html
At least I hope I did remember this right :)
> it seems to have worked.
Thats good :)
> i know its not much but i am pretty damn happy.
> my first join.. i will remember it always :).
When taking the first step, then the next one will be easier, I think it was
like that when I learned to walk :P Congrats.
//Aho
Navigation:
[Reply to this message]
|