| Author |
Topic |
|
Dajka
Starting Member
5 Posts |
Posted - 2011-10-20 : 18:06:59
|
| Hi,I'm new to sql so sorry in advance if I say something wrong. My issue is the following: I'm trying to connect 3 tables where 2 is connected with a simple join, but the third tabel does not neccessarily have a record in it with the requested data. I was trying to do something like this... I dont know if it helps you to understand what I'm trying to do... Maybe its totally useless...SELECT n.Tipus, n.SubjectId, n.Nev, n.Timestamp, k.Tipus, t.Timestamp (FROM notifikaciok AS n, kovetes AS k, nezett_log AS t WHERE k.Nev = ? AND (n.SubjectId = k.SubjectId OR n.Nev=k.SubjectId) AND n.Timestamp>k.RegTime) LEFT JOIN t ON n.SubjectId=t.Nezett WHERE t.Nev=k.Nev ORDER BY n.Timestamp DESCThanks for your help in advance |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Dajka
Starting Member
5 Posts |
Posted - 2011-10-20 : 18:22:41
|
| Sorry for the multi language.I hope this is fine.notifikaciok table: (`NotId`, `Tipus`, `SubjectId`, `Nev`, `Timestamp`) VALUES(82, 'HSZ', '1022', 'Dajka', 1319067674)kovetes table:(`KovId`, `Nev`, `SubjectId`, `Tipus`, `LastVisit`, `RegTime`) VALUES(153, 'Ventura', '403', 'FAV', 1319067165, 1319067165)nezett_log table: (`Nev`, `Nezett`, `Timestamp`) VALUES('Ventura', '907', 1316740495) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Dajka
Starting Member
5 Posts |
Posted - 2011-10-20 : 18:45:09
|
| Okay I’ll try to explain the problem... (Sorry for my English)So the situation is the following... I'm trying to create a notification system, where all the events get into the 'notifikaciok' table. I want to order this table by time and then query it through to get the related events for each individual user. every user can register for events in the 'kovetes' table. So I want to return those rows from 'notifikaciok' where the (n.SubjectId = k.SubjectId OR n.Nev=k.SubjectId) This is where my issue comes in.Now I have a third table 'nezett_log' containing the information about when was the last time 'Timestamp' the user saw the appropriate event, but if the user never visited that page before, then there is going to be no record of this in this table. Even though there is no record, I still want to return all the other fields from the other two tables. I hope this makes sense... |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Dajka
Starting Member
5 Posts |
Posted - 2011-10-20 : 18:55:23
|
| As you can see I was trying to do this in the SQL what I posted in my first comment, but it seems to have some syntax error what I cant figure out. Could you help me with that? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Dajka
Starting Member
5 Posts |
Posted - 2011-10-20 : 20:01:08
|
| wonderful!Thank you very much.This is exactly what I needed.work like a charm ;) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|