The Little Guy Posted March 24, 2009 Share Posted March 24, 2009 How do I create a column not in the table in a select statement, then assign it a temporary value? Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/ Share on other sites More sharing options...
trq Posted March 24, 2009 Share Posted March 24, 2009 What? Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-792440 Share on other sites More sharing options...
Mchl Posted March 24, 2009 Share Posted March 24, 2009 SELECT *, 'temporary value, a function, a subquery, whatever' AS additionalColumn FROM table Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-792454 Share on other sites More sharing options...
The Little Guy Posted March 24, 2009 Author Share Posted March 24, 2009 What I was looking for was this query: Â ( SELECT id, sender, 'mailbox' as `table`, subject, inbox, date FROM mailbox WHERE owner = '$_id' AND status = '0' ) UNION ( SELECT f.id, req as sender, 'friends' as `table`, 'Friend Request' as `subject`, CONCAT(u.first,' ',u.last) as `inbox`, date FROM friends f LEFT JOIN users u ON (f.req = u.id) WHERE rec = '$_id' AND acc = '0' ) ORDER by date Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-792947 Share on other sites More sharing options...
Mchl Posted March 24, 2009 Share Posted March 24, 2009 That's more like 'temporary rows'... Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-792986 Share on other sites More sharing options...
The Little Guy Posted March 24, 2009 Author Share Posted March 24, 2009 That's more like 'temporary rows'... Â oh... I see it as a column, but w/e all's good! Â Would you keep this query, or is it very resource demanding? Â I am going to make a second query that does something similar, but all it will do is generate a number of unread inbox info. Â The one I gave in my previous post will be used when the user is viewing his/her mailbox, and the other will be when he/she is not. Â So, will using these slow my site down, when I have lets say 1 GB for each table? Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-793004 Share on other sites More sharing options...
Mchl Posted March 24, 2009 Share Posted March 24, 2009 UNION is basically like running two queries one after another. So if the queries used don't slow you down, then the union won't either. Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-793007 Share on other sites More sharing options...
The Little Guy Posted March 24, 2009 Author Share Posted March 24, 2009 Well currently, I have only a few rows in each table, so would it be possible to tell for future reference? Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-793010 Share on other sites More sharing options...
Mchl Posted March 24, 2009 Share Posted March 24, 2009 http://dev.mysql.com/doc/refman/5.0/en/query-speed.html Quote Link to comment https://forums.phpfreaks.com/topic/150841-solved-create-temporary-column/#findComment-793023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.