alandr
alandr

Reputation: 43

from sql query to mysql equivalent

Please, i have this query which is in sql

select sum(lhd.sasih)-sum(lhd.sasid) as sasi,lhd.kartllg as kartllg
from e2013..levizjehd lhd,supersick_db..produkt as prod
where  lhd.kartllg=prod.kodfinance
group by lhd.kartllg

I need to write it's equivalent but in mysql... I get this error:

Invalid object name 'e2013..levizjehd'.

What i need is to translate it in mysql query, but i don't know what .. stand for in sql. I'd appreciate some help please.

How i connect

$host="192.168.10.250\\f501";
$uid="sa";
$passVal="";
$database="SUPERSICK_DB";
$objConnect = odbc_connect("Driver={SQL Server};Server=$host;Database=$database;",$uid, $passVal ) or die("Connection could not established");

Thanks!

Upvotes: 1

Views: 90

Answers (2)

Andrew Richards
Andrew Richards

Reputation: 59

I think Angelo's covered the question but note that the following aren't equivalent:

SUM(lhd.sasih) - SUM(lhd.sasid)
SUM(lhd.sasih - ldh.sasid)

These expressions can potentially return different results if either column is nullable: aggregates ignore nulls. E.g. if row one is {10, null} and row two is {100, 50} the first returns 10 + 10 - 50; the second 100 - 50.

Upvotes: 1

Angelo Fuchs
Angelo Fuchs

Reputation: 9941

Seems like it is referring the database name. So like 'e2013' is one DB and 'supersick_db' is another. The first contains the 'levizjeh' table the other one the 'produkt' table.

If you have both tables inside the same mysql than you can skip the name and the .. altogether.

SELECT SUM(lhd.sasih)-SUM(lhd.sasid) AS sasi, lhd.kartllg AS kartllg
FROM levizjehd lhd, produkt prod
WHERE lhd.kartllg = prod.kodfinance
GROUP BY lhd.kartllg

You can improve the query like this:

SELECT SUM(lhd.sasih)-SUM(lhd.sasid) AS sasi, lhd.kartllg AS kartllg
FROM levizjehd lhd
INNER JOIN produkt prod ON lhd.kartllg = prod.kodfinance
GROUP BY lhd.kartllg

Upvotes: 1

Related Questions