How to create virtual column using MySQL SELECT

0 votes
If I do SELECT a AS b and b is not a column in the table, would query create the "virtual" column?

in fact, I need to incorporate some virtual column into the query and process some information into the query so I can use it with each item later on.
Oct 20, 2020 in PHP by kartik
• 37,520 points
3,512 views

1 answer to this question.

0 votes

Hello,

Something like:

SELECT id, email, IF(active = 1, 'enabled', 'disabled') AS account_status FROM users

This allows you to make operations and show it as columns.

you can also use joins and show operations as columns:

SELECT u.id, e.email, IF(c.id IS NULL, 'no selected', c.name) AS country
FROM users u LEFT JOIN countries c ON u.country_id = c.id

Hope it helps!!

answered Oct 20, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
1 answer

How to alter a MySQL column to be AUTO_INCREMENT?

Hello @kartik, Try this: ALTER TABLE document MODIFY COLUMN ...READ MORE

answered Aug 19, 2020 in PHP by Niroj
• 82,840 points
2,888 views
0 votes
1 answer

How to delete a certain row from mysql table with same column values?

Hello @kartik, Add a limit to the delete query delete from orders where ...READ MORE

answered Aug 26, 2020 in PHP by Niroj
• 82,840 points
1,684 views
0 votes
1 answer

How to create a database using PDO in PHP?

Hello @Hitesh, Yes, you can create a database using ...READ MORE

answered Nov 9, 2020 in PHP by Niroj
• 82,840 points
6,409 views
0 votes
0 answers

How to create cron job using PHP?

 I want to create a cron job ...READ MORE

Jun 13, 2022 in PHP by narikkadan
• 63,600 points
1,617 views
0 votes
1 answer

jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?

Hello, In the error callback or $.ajax you have three ...READ MORE

answered Apr 27, 2020 in Java-Script by Niroj
• 82,840 points
4,190 views
0 votes
1 answer

How do I pass command line arguments to a Node.js program?

Hello @kartik, If your script is called myScript.js ...READ MORE

answered May 5, 2020 in Java-Script by Niroj
• 82,840 points
3,243 views
0 votes
1 answer

Error:Issue when trying to use IN() in wordpress database

Hello @kartik, Try this code : // Create an ...READ MORE

answered May 8, 2020 in PHP by Niroj
• 82,840 points
1,116 views
+2 votes
1 answer

How do I debug Node.js applications?

Hello @kartik, Use node-inspector  from any browser supporting WebSocket. Breakpoints, ...READ MORE

answered Jul 8, 2020 in Node-js by Niroj
• 82,840 points
1,028 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
3,357 views
0 votes
1 answer

How to get a list of user accounts using the command line in MySQL?

Hello @kartik, Use this query: SELECT User FROM mysql.user; Which ...READ MORE

answered Aug 18, 2020 in PHP by Niroj
• 82,840 points
1,566 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP