user3560827
user3560827

Reputation: 694

MySQL Single Row Multiple Columns Multiple Tables

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).

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

Upvotes: 0

Views: 205

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269803

Is this what you want?

SELECT u.*, p.imageurl
FROM users u cross join
     picture p
WHERE p.profilepicture LIKE '1';

Upvotes: 1

Related Questions