0

I want to select all fields of several table and fetch result separate but mysql return all rows together:

SELECT prod_product.*
  ,pub_comment.* 
FROM prod_product 
INNER JOIN pub_comment ON (prod_product.id = pub_comment.itemId) 
WHERE prod_product.id=7744

Is there any way that i could fetch each table rows separately?

I try @prod:=prod_product.*, @comment:=pub_comment.* but mysql didn't allow me to store more than 1 row.

1
  • @user703617: remember to accept correct answer if you find one. Commented Apr 12, 2011 at 9:10

2 Answers 2

1

Execute two queries:

select * from prod_product WHERE prod_product.id=7744

and

select * from pub_comment WHERE pub_comment.itemId=7744

A single query always return single rows containing two table fields.
Anyway: what is the problem of having columns together in a single row? If you have problems with their names you can use aliases.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi marco , Thanks for your answer but it's 2 queries and i need to decrease my db fetches, maybe i have to do it
@user703617: As I told you, why can't you use a single query? Which is the problem of having columns together?
@user703617: if you give us some detail, we can help you better :)
0
SELECT @prod:= CONCAT_WS(',',prod_product.field1,prod_product.field2,...)
  ,@comment:= CONCAT_WS(' ',pub_comment.field1,pub_comment.field2,....) 
FROM prod_product 
INNER JOIN pub_comment ON (prod_product.id = pub_comment.itemId) 
WHERE prod_product.id = 7744

Note that CONCAT_WS will separate your fields and CONCAT will just smash then together.

1 Comment

Oh, I must warn you about concat_ws, it gave me a nasty collation error where the table was in LATIN1 and the system is set to UTF8 then the result will be in UTF8, which will not be INSERTed into a LATIN1 table. If you get this workaround is to use CONCAT(field1,' ',field2,' '...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.