diff --git a/lib/orient_db/methods/edge_methods.rb b/lib/orient_db/methods/edge_methods.rb
index dd207325ed98ce206a8231374e10d9c62dbc4abc..9d00cf9a397b1c2979c1de96b76a9f54a1fbefa3 100644
--- a/lib/orient_db/methods/edge_methods.rb
+++ b/lib/orient_db/methods/edge_methods.rb
@@ -5,7 +5,7 @@ module OrientDb
       ##
       # Count the number of edges existent
       def get_in_edges_count(edge_class, id)
-        result = connection.query "SELECT COUNT(@rid) FROM #{edge_class} WHERE in = #{id}"
+        result = connection.query "SELECT IN('#{edge_class}').size() AS COUNT FROM Object WHERE @rid = #{id} LIMIT 1"
         result.first["COUNT"].to_i
       end