Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Null or not null question

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Can somenone help me with this query



Nothing is showed.....any help?

Thanks
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


You do an inner join, which means you will not get any rows where idequipamento is NULL, and then remove all rows where it is NOT NULL in the WHERE clause.

And that last line is not valid SQL (OR AND?), but I expect that's a typo on your part as it would never execute.
 
Gil Carvalho
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you

Yes, i understand but i need that Inner Join, who gonna gives me the name..

Any solution for that?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the purpose of these conditions in the WHERE clause?

If you execute the following query, do you get results? And could you share these results (or some sample data) and indicate which ones you want to be removed from the results?
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gil Carvalho wrote:Thank you

Yes, i understand but i need that Inner Join, who gonna gives me the name..

Any solution for that?



If you need things where the `req_material_reserva`.`idequipamento` is null, then you need to write a SELECT that supplies rows where they can be null.
In order for that to be the case then you need outer joins.
 
Gil Carvalho
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the result of this query(image)


This is caused by an if statement i need in my java code
I must check if school booking has a equipment or just a classroom
This is my book table(image)

So i an user book just a classroom without equipment the result is null in idequipamento field if he books with equipment i have the id of that equipment

Example

idreserva idutilizador idsala idtempoInicio idtempoFim data idequipamento
--------- ------------ ------ ------------- ---------- ---------- -------------
116 1223 4 13 14 2015-03-20 1
125 1 1 11 11 2015-03-20 5
126 1 1 11 11 2015-03-20 (NULL)
127 1261 1 11 11 2015-03-20 6
128 1261 1 13 14 2015-01-26 3

So i want to my query checks if i have an "Null" value it open a java window, if i don't have open me another one.



sql.jpg
[Thumbnail for sql.jpg]
Query result
table.jpg
[Thumbnail for table.jpg]
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said, if you want to include eq_material_reserva rows that have no mapping to (for example) a row in the req_material_equipamento table then your query joining those two tables needs to be an outer join.

If you don't understand what that means then you need to do some reading up on SQL queries and how joins work.
I don't have any handy links for that sort of thing, though.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:If you don't understand what that means then you need to do some reading up on SQL queries and how joins work.
I don't have any handy links for that sort of thing, though.


In my opinion, w3schools is always a good starting point. Besides an explanation you always have an example to try it yourself. Here you'll find the info about sql joins.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic