• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

[fixed] Urgent SQL question: Is it possible to do this?

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two tables- table1 & table2

I want to join them with 127.0.0.3 SHOWN in NEW TABLE even it have no
hits (in table2)
mysql> select a.ip,name,time,sum(hits) from table1 a left join table2 b
on a.ip=
b.ip group by a.ip,a.name;

But if I specify the time ( > 2000 ) using where time>'2001' , I can't
get what my want (Also show 127.0.0.3)
What can the SQL do to do what I want? Many thanks!!
mysql> select a.ip,name,time,sum(hits) from table1 a left join table2 b
on a.ip=
b.ip where time>'2001' OR time=null group by a.ip,a.name;

pls read here if you cant see above:
http://www.hk3s.com/db.txt
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 18, 2003: Message edited by: Dirk Schreckmann ]
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At least in Oracle you would say:

I am not sure about mysql
Please let us/me know.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please send the table descirptions i.e., using desc table1 and desc table2. And can we also know the mysql version you are using?
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to join them with 127.0.0.3 SHOWN in NEW TABLE even it have no
hits (in table2)
mysql> select a.ip,name,time,sum(hits) from table1 a left join table2 b
on a.ip=
b.ip group by a.ip,a.name;

But if I specify the time ( > 2000 ) using where time>'2001' , I can't
get what my want (Also show 127.0.0.3)
What can the SQL do to do what I want? Many thanks!!
mysql> select a.ip,name,time,sum(hits) from table1 a left join table2 b
on a.ip=
b.ip where time>'2001' OR time=null group by a.ip,a.name;

PS: Pls be remind that this all can be do in MSSQL but not MYSQL. Thanks
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 18, 2003: Message edited by: Dirk Schreckmann ]
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made this one, seem to be work, need to test:
SELECT a.ip, name, SUM(hits)
FROM table1 a LEFT JOIN
table2 b ON a.ip = b.ip
WHERE time > '2001' OR
time = NULL
GROUP BY a.ip, a.name
UNION
SELECT c.ip, c.name, 0
FROM table1 c
WHERE NOT EXISTS
(SELECT 'X'
FROM table2 d
WHERE d .ip = c.ip)
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic