473,378 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

select colum

ddtpmyra
333 100+
Hi,

Is there a way where you can select columname that is equal to row value?
for instance i have tablename PET
Expand|Select|Wrap|Line Numbers
  1. --------------------------
  2. | CAT | DOG | BIRD |
  3. --------------------------
  4. | dog | dog | dog |
  5. ----------------------
  6. | cat | cat | dog |
  7. ---------------------
  8. | bird | dog | dog |
  9. ---------------------
  10.  
now i want to select the column name that is equal to row let say
selct * from pet where
column = cat
row = cat


is there a way you can do that?
Jan 24 '09 #1
9 1920
tharden3
916 512MB
Correct me if I'm wrong, but I believe it is:
SELECT *
FROM Pet
WHERE (CAT="cat");
Jan 24 '09 #2
ddtpmyra
333 100+
I think I didn't explain very well, what I wanted to do a result that tells me the column name that has cat value.
Jan 24 '09 #3
Atli
5,058 Expert 4TB
You don't select column names based on the row data.
You select row data based on column names.

If you need to do the opposite, odds are your table design is somewhat off.

Could we see the CREATE TABLE command you used to create it?
We might be able to suggest a better method.
Jan 24 '09 #4
ddtpmyra
333 100+
Actually, I have a website that the user assigned the approver names and everytime they check box and hit the save button it assigned 'Y' on its equivalent variable where the name of the persons is the column, below is how I created the table

DROP TABLE IF EXISTS `test`.`approval`;
CREATE TABLE `test`.`approval` (
`ID` int(10) unsigned NOT NULL auto_increment,
`JamesLeory` char(1) NOT NULL default '',
`MaricarEdwards` char(1) NOT NULL default '',
`LizaJones` char(1) NOT NULL default '',
PRIMARY KEY (`FileID`)
) TYPE=MyISAM;
Now I wanted to select the column names (person names) that has 'Y' value can I do that?
Jan 25 '09 #5
tharden3
916 512MB
The names should not be set up as the fields, but rather data in a column. 'Y' can then be assigned in a matching column. Not trying to make it difficult on you, but I think you need to rethink the structure here.
Jan 25 '09 #6
Atli
5,058 Expert 4TB
Yea, tharden is right. You should never use actual data (like a approver's name) as the name of a table or a field.

In your case, a many-to-many (N:M) relationship would probably be the best solution.

That is; you should have one table to store a list of approvers. A second to keep a list of whatever you need them to approve of. And a third to link the two together.

Consider this:
Expand|Select|Wrap|Line Numbers
  1.  Table: Approver
  2. +------------+--------------+
  3. | ApproverID | ApproverName |
  4. +------------+--------------+
  5. | 1          | John         |
  6. | 2          | Jane         |
  7. | 3          | Mike         |
  8. +------------+--------------+
  9.  Table: Items
  10. +---------+-----------+
  11. | ItemID  | ItemName  |
  12. +---------+-----------+
  13. | 1       | FirstItem |
  14. | 2       | ItemTwo   |
  15. +---------+-----------+
  16.  Table: ItemApproval
  17. +---------+------------+------------+
  18. | ItemID  | ApproverID | Approved   |
  19. +---------+------------+------------+
  20. | 1       | 1          | Y          |
  21. | 1       | 2          | N          |
  22. | 2       | 1          | N          |
  23. | 2       | 2          | Y          |
  24. | 2       | 3          | Y          |
  25. +---------+------------+------------+
This is a standard N:M relationship, with an added "Approved" value for each link in the "ItemApproval" table.

And to prevent each Approver from approving each item more than once, you would use the ItemID and the ApproverID in the link table as a joint Primary-Key (or a unique-key, if you prefer that).
Jan 25 '09 #7
ddtpmyra
333 100+
Hi Atli,

These getting clearer now, but what if the user will select who will be the approver for the items, where that will be stored? should it be on the Table:Items and insert the approver ID?

thanks for your support,
DM
Feb 17 '09 #8
Atli
5,058 Expert 4TB
If each item should only be able to be approved by a single, preselected approver, then you wouldn't need the N:M relationship.

For that scenario, a one-to-many (1:N) relationship would do fine.
The ID of the selected approver could simply be added to the Item table, as well as the value indicating whether the item has been approved.

Like:
Expand|Select|Wrap|Line Numbers
  1.  Table: Approver
  2. +------------+--------------+
  3. | ApproverID | ApproverName |
  4. +------------+--------------+
  5. | 1          | John         |
  6. | 2          | Jane         |
  7. | 3          | Mike         |
  8. +------------+--------------+
  9.  Table: Item
  10. +---------+-----------+---------------+------------+
  11. | ItemID  | ItemName  | ApproverID_FK | Approved   |
  12. +---------+-----------+---------------+------------+
  13. | 1       | FirstItem | 1             | TRUE       |
  14. | 2       | ItemTwo   | 2             | FALSE      |
  15. +---------+-----------+---------------+------------+
Feb 18 '09 #9
ddtpmyra
333 100+
Thank You Atli! This make more clearly how to contruct my tables
Feb 18 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mr_burns | last post by:
hi, how do i do a SELECT statment that will just query a table to find the row with the maximum of a declared field. for example, if i have a table of customers and i would like to get the value...
1
by: Henrik | last post by:
hi how can i hide a row or colum still containing data in a msflexgrid -- Best regards henrik
3
by: Jacinle Young | last post by:
Hi If I have a table with two colum ITEM and NAME, like the following ITEM NAME ======= ============ Apple Nancy Orange Nancy Lemon Margaret Orange ...
7
by: JohnA | last post by:
Dear all, I'm trying to compose a query, but I don't know how to express the statement. I have 4 tables: Customers, Orders, Order Details and Products. Each customer has many orders and each...
0
by: xiaozozo | last post by:
also, i would like to do some URL tagging with the retrieved colum value such as: http://localhost/PM/message.aspx?id=123 how do i go about writing the url tagging codes? samples will do :...
5
by: mail | last post by:
Urgent help needed! I moved an application from ASP+ACCESS to ASP+MS SQLSERVER and I have the following problem: If the join on two tables results on duplicate colum names (which appear in...
1
by: inamul | last post by:
I want to select CheckBox based on data retrieved from mysql database table. Could anyone show me the simple way of doing it. Data store in table under colum "sectionOfInterest" is shown below...
4
by: DaveRook | last post by:
Hello I am bringing some results from SQL server 05 into my web page. For simplicity, my database has 2 colums, PartNumber and Size, and has the following information: PartNumber: A1 Size:...
1
by: Carcinosi | last post by:
Hello, I have a MySQL 5.0 Database used for management of my service, with 13 tables. The two tables most important now are "customers" and "cust_packages". The table "customers" has one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.