0

I have two tables 'table A' and 'table B', I would like to select all columns from Table A (10 columns) and select 1 column from Table B so that I have 1 row with a total of 11 columns (10 from Table A and 1 from Table B).

  • I would like to avoid using 'As alias_name' and use original column name
  • My tables have no common ID columns
  • Both my select statements returns 1 row each (1 row from Table A and 1 row from Table B)
  • I just want to take my result from first select statement and join the result with second select statement to have multiple columns (1 row) and NOT a single column (so I will not be using UNION, perhaps INNER JOIN but not sure how to use it?)

The following statement is close to what I require - It returns 2 columns (alias_name, alias_imageurl) from 2 tables:

SELECT (SELECT name FROM `users`) AS alias_name,(SELECT imageurl FROM `pictures` WHERE profilepicture LIKE '1') AS alias_imageurl

The problem with the above (besides being forced to use an alias for column names) is that I can only return 1 column from Table A instead of all because the below query returns an error: Operation should contain 1 column(s)

SELECT (SELECT * FROM `users`),(SELECT imageurl FROM `pictures` WHERE profilepicture LIKE '1') AS alias_imageurl
1
  • You have a very unusual set of requirements. Can you motivate why you think these are a good idea? Commented Nov 17, 2016 at 19:30

1 Answer 1

1

Is this what you want?

SELECT u.*, p.imageurl
FROM users u cross join
     picture p
WHERE p.profilepicture LIKE '1';
Sign up to request clarification or add additional context in comments.

2 Comments

Unrecognized keyword. (near "cross" at position 36)
@user3560827 . . . MySQL definitely supports cross joins: dev.mysql.com/doc/refman/5.7/en/join.html.

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.