Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null or not null question

 
Gil Carvalho
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can somenone help me with this query



Nothing is showed.....any help?

Thanks
 
Dave Tolls
Ranch Hand
Posts: 2100
15
  • Mark post as helpful
  • send pies
  • 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: 79
  • Mark post as helpful
  • send pies
  • 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?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 2100
15
  • Mark post as helpful
  • send pies
  • 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: 79
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 2100
15
  • Mark post as helpful
  • send pies
  • 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: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic