Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to select rows ?

Status
Not open for further replies.

bonosa

Programmer
May 19, 2004
76
US
I am trying to create a table with certain select rows from another table. One column in the original table is called ID. I want only those rows with certain ID values (say 56 , 78, 89, 90) etc to be in the new table.
How do I do this?
Thanks,
sb
 
are you using phpMyAdmin? if you are, the easiest way would be to use the Export feature. I can't recall if it allows you to export into a new table, but if not, you can just export, then run the SQL statement it creates.
 
No. I'm trying to create a query like

SELECT * FROM sometable WHERE ID = 10 AND...

I'm writing c++ code with this.

doing
WHERE ID = 10 AND ID = 12 AND ID = 45
doesnt work and I can see why. So whats the right way to do this?
Thanks,
sb
 
Oh and I also tried WHERE with OR (not AND) That didnt work either
 
well, the way your doing it is checking the 1 id field for several different values. you need to set it up like this:

Code:
SELECT * FROM sometable AS sometable_1, sometable AS sometable_2 sometable AS sometable_3 WHERE sometable_1.id = 10 AND sometable_2.id = 12 AND sometable_3.id = 45

funny cause that's exactly the same thing i've been trying to do and i just got help from r937. I am now passing that on to you :)
 
Hmmmm.
I'm not sure:
I should have posted exactly what I am doing:

CREATE TABLE newtable SELECT * FROM sometable WHERE ID = 10 OR ID = 12 OR ID = 19

In your excerpt above what are sometable1, sometable2 etc? All I have at the moment is the master table 'sometable'.
Do I need to create these other tables? Thanks for helping.
sb
 
Yes. These values definitely exist in the table. What I get back from the query is ALL the rows!
sb
 
where it says "AS" it is aliasing your only mastertable as a new name so you can check the one ID field for multiple values. its still using the same 1 table, but each WHERE statement will ignore the results produced from the one before, allowing you to get all records with each ID.
 
Never mind. It works now with the ORing. I dont know what I did wrong before.
Sorry bout that and thanks for all the help,
sb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top