[英]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). 我有两个表“表A”和“表B”,我想从表A中选择所有列(10列),然后从表B中选择1列,这样我就有1行,总共11列(表A和表B中的1)。
The following statement is close to what I require - It returns 2 columns (alias_name, alias_imageurl) from 2 tables: 以下语句与我的要求很接近-它从2个表中返回2列(alias_name,alias_imageurl):
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) 上面的问题(除了被迫为列名使用别名外)是我只能从表A中返回1列,而不是全部,因为下面的查询返回错误:操作应包含1列
SELECT (SELECT * FROM `users`),(SELECT imageurl FROM `pictures` WHERE profilepicture LIKE '1') AS alias_imageurl
Is this what you want? 这是你想要的吗?
SELECT u.*, p.imageurl
FROM users u cross join
picture p
WHERE p.profilepicture LIKE '1';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.