1) How to write the below SQL query in Magneto collection :

SELECT * FROM 'table1' WHERE active=0 AND '2014-07-08' between 'not_available_from_date' and 'not_available_to_date'


2) Also how to write this SQL query in Magneto Collection :

Select sum(qty + product_id - any_other_columns) as total from table2  GROUP BY product_id; 


Without using ->columns('  ') function.

Thanks for your help


Question: Get raw output from web server
Answer: I imagine it could be done with wget but I know how to do this with curl. yum install curl or whatever for your OS if you don't already have it installed:

curl -vv http://thewebsiteinquestion.com


The output will show you the raw response from the server, including the headers and body, like you wanted. This is purely a preference thing but I've generally found curl easier and more intuitive to use for testing and development than wget.

Sometimes it's also helpful to use telnet and speak raw HTTP. As a sysadm/dev I find this invaluable. For example:

$ telnet google.com 80
Trying 74.125.239.0...
Connected to google.com.
Escape character is '^]'.
GET / HTTP/1.0
Host: google.com

HTTP/1.0 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Thu, 20 Sep 2012 22:31:32 
... the rest ommitted


All you need to type by hand is the GET / HTTP/1.0 and Host: google.com lines. Then hit enter twice. This way you really see the full response from the remote HTTP server, with nothing getting in the way. As you play around with it you learn better how HTTP works, and will never get confused when redirects are happening (as you can see is happening above, via the 301 HTTP status and Location header), and your tool (browser, wget, curl) is handling them automatically for you.

Edit: how to pass GET parameters using telnet. Just add them to the path you're GETting when you speak HTTP:

$ telnet thewebsite.co.uk 80
Trying 95.131.67.221...
Connected to thewebsite.co.uk.
Escape character is '^]'.
GET /?foo=bar HTTP/1.0
Host: thewebsite.co.uk 

HTTP/1.1 200 OK
Date: Fri, 21 Sep 2012 17:43:27 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
Last-Modified: Mon, 01 Jun 2009 20:10
...


To do a POST query, you have to calculate the length of the submitted data and put it in Content-Length, and that looks like:

$ telnet www.yahoo.com 80
Trying 72.30.38.140...
Connected to ds-any-fp3-real.wa1.b.yahoo.com.
Escape character is '^]'.
POST / HTTP/1.0
User-Agent: telnet
Host: www.yahoo.com
Accept: */*
Content-Length: 8
Content-Type: application/x-www-form-urlencoded

p=foobar
HTTP/1.0 200 OK
Date: Fri, 21 Sep 2012 17:57:35 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Cache-Control: private
X-Frame-Options: SAMEORIGIN
...