Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Inner Join

Status
Not open for further replies.

jacktripper

Programmer
Dec 5, 2001
124
US

I created this inner join query in SQL server, and it seems to work just fine. But, when I try the same thing in mySQL (duplicate database) it gives me an error. I've never tried join statements with mySQL... any help would be nice! Also, is there any free software out there for building relationships and creating queries for mySQL?

SELECT orders.*, orderscart.*, company.*, accounts.*, company.companyid AS Expr1, orders.ordernum AS Expr2 FROM orderscart INNER JOIN orders ON orderscart.ordernum = orders.ordernum INNER JOIN accounts INNER JOIN company ON accounts.companyid = company.companyid ON orders.companyid = company.companyid WHERE (company.companyid = 'bctcom') AND (orders.ordernum = '8975')
 
I reorganized your query:

Code:
SELECT
	orders.*, orderscart.*, company.*, accounts.*, company.companyid AS Expr1, orders.ordernum AS Expr2
FROM
			orderscart
		INNER JOIN
			orders
		ON
			orderscart.ordernum = orders.ordernum
	INNER JOIN
			accounts
		INNER JOIN
			company
		ON
			accounts.companyid = company.companyid
	ON
		orders.companyid = company.companyid
WHERE
	(company.companyid = 'bctcom') AND (orders.ordernum = '8975')


Part of it is that you have an inner join comprised of two inner joins. MySQL can combine joins, but only serially:

Code:
SELECT
	orders.*, orderscart.*, company.*, accounts.*, company.companyid AS Expr1, orders.ordernum AS Expr2
FROM
				orderscart
			INNER JOIN
				orders
			ON
				orderscart.ordernum = orders.ordernum
		INNER JOIN
			company
		ON
			orders.companyid = company.companyid
	INNER JOIN
		accounts
	ON
		accounts.companyid = company.companyid
WHERE
	(company.companyid = 'bctcom') AND (orders.ordernum = '8975')



Want the best answers? Ask the best questions: TANSTAAFL!!
 
Muchos gracias! It worked just fine. I will have to remember this for future reference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top