Anyone knows coding here in PHP+MySQL?

August 4th, 2016

I have a table with four columns… A B C D
I want the B,D combination to be unique while inserting the records. For example, if there was a record already, then I don’t want to insert that. Is this a database issue or do I have to do some SELECT in php to see if I get any records and then insert?
Also, how would I use the distinct for multiple columns? At present, if I say SELECT DISTINCT(A), it gives me all records not repeating in column A but I want to do this on multiple columns… Is there a way for this?

Answer #1
Hmmmm, im not too sure because I cant test, but this doesnt work????
SELECT DISTINCT (A,B,C,D)
FROM xxxxxx <<<<<(your table name)
Sorry im not sure about the php thing, I only know sql
Answer #2
THank you… Even that is sufficient… I have these columns right… I’m writing a similar query
Select Distinct (B,D) from table_name;
This gives me 5000 rows but Select A,B,C,D from table_name group by B,D;
gives me 4950 rows… And I don’t understand why… Can you help me please?
Actually I wanted to get all the four columns as a list i.e. A,B,C,D but wanted to apply Distinct only on B and D but didn’t know how to do that so framed a group by statement and that was showing some weird behavior…
Answer #3
SELECT DISTINCT (B,D) , A, C
FROM table_name;
Sorry im not an sql whiz but try that. I dont have anything to test it out on and I dont have many notes on DISTINCT. Im a second year I.T student so if that doesnt work, maybe theres a sql master out there who can help ???
Answer #4
It says “Operand should contain 1 column(s)” Not sure what I need to do if it says like that…
Answer #5
what type of database you using. Oracle??
Answer #6
Oops… Sorry I should’ve mentioned that… Its MySQL…
Answer #7
hmmm, sorry dude. Ive been going through all my books and searching on the web, but I cant find an answer. Hopefully someone else can help out
Answer #8
Alright… Thank you so much for your time though… Advanced Happy Christmas…
Answer #9
Actually I did something that worked:
ALTER TABLE table_name ADD UNIQUE KEY(B,D);
This is working now

 

| Sitemap |