I have these 2 tables (1st let's say table1 and 2nd table2) I need to do the follwings operations on these 2 tables for a project tomorrow! If anyone could help, would be much appreciated! I need em in querry so I can copy paste it for project!
1.Show all from "Parinti" that have "Angajator" as "Firma1"
2.Show all from "Copil" that have "Parinte1"
3.Update the field "Data_creare" from table2 with current date for "Copil" that have "Parent1"
4.Delete all from "Copil" that have "Data_Naster" = 10.01.2013
5.last I need to sort the values from table2 column "Copil" ascending ascending depending of field "Data_nastere"
You'll have to at least try to solve it yourself (you learn nothing from copy paste).
Write again if you get stuck (show us what you've tried and whats now working), and we'll try to point you in the right direction.
SELECT Parinte FROM table1 WHERE Angajator = "Firma1"
SELECT table2.Copil, table1.Parinte
FROM Table2
INNER JOIN Table1
ON tabel2.Id_Parinte = Tabel1. (and now I don't know if it's ID or Parinte!!!!!!!!!!!)
3.UPDATE table2 SET Data_creare = GETDATE () WHERE ID_Parinte = 1 (don't know if it's right)
4. I don't know how to filter/sort by date
5. same as 4
almost correct, just replace double quotes with single quotes
you know that you need "inner join" - excelent. this shows how it works.
this will work, but only because you already know id_parinte is 1. you would want probably want to join to table 1 thru the id, to find parinte field = 'Parinte1'. to do this you could use the "exists" clause in the where section of your update statement. this shows how it could be done
if field is og type date, you can use cast like this: where data_naster=cast('2013-01-10' as date)
sorting is done with the "order by" clause. see here
Finally you would want to test your queries - Get you own copy of mssql og do it online here
correction: you want to show all field, so either list all fieldnames or use "select *"
this is correct way of joining. you just need to specify fields you want to see (or select *) and that you want records/rows where parinte is "Parinte1"
I give up, I aleready mixed up the little that I know! and I am screw-ing up everything! why won't you just write it down bitsmed!, I am sure it takes you 5 mins to make all the points correct !And only 6 hours till I have to go to school!
You didn't screw up - I think you were doing well. We all have to learn, but we don't learn anything by copy/paste. I think it's a pitty that you give up, but hey - If you don't care, why should I
Your solution does also jork - nice job
The error you got before when using "top" could indicate you're using other database engine as mssql. If you are using mysql, the equivalent method of top is limit:
select copil
from table2
order by data_nastere desc
limit 1
;
I would use international date standard (I think it's ISO 8601) which defines date as yyyy-mm-dd. So I would do:
delete from table2
where data_nastere=cast('2013-01-10' as date)